Re: Re: how do you get to do multiple mysql queries concurrently?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Thu, January 31, 2008 1:40 am, Per Jessen wrote:
> Richard Lynch wrote:
>
>> On Mon, January 28, 2008 2:52 pm, Per Jessen wrote:
>>> True again. However, I was commenting on your assertion that
>>> "Process
>>> forking has EVERYTHING to do with thread safety", which I will stay
>>> is
>>> wrong.  When you fork another process, you don't need to worry
>>> about
>>> whether your code is thread-safe or not. You don't have to be
>>> reentrant, you could even use self-modifying code if you felt the
>>> urge.
>>
>> Perhaps I mis-remember my C days, but I'm pretty sure it's trivial
>> to
>> write a "fork" program in which both parent and child attempt to
>> utilize the same "global" resource as if they have exclusive access
>> and crash your program.
>
> I think you are mis-remembering, yes.  When your fork() call returns,
> you have two separate processes, your child process being an exact
> copy
> of your parent process. (mostly, see "copy-on-write").  The only thing
> they share at this point are open file descriptors which have also
> been
> copied, so they obviously point the the same file(s).

So they could easily corrupt the file by making assumptions about it.

More importantly, if you build and initialize some data structures
before you fork, and if they each assume they have exclusive access to
said data structures, your program ends up not being "thread-safe"

You can call it something else if you like, but it's essentially the
same problem.

>> Sure smells like a thread-safety issue to this naive reader...
>> fork() manages to "do the right thing" for many common resources,
>> but
>> it doesn't handle all of them.
>> If you expect to have two processes running the same lines of codes
>> at
>> once, you need to worry about thread safety just as if there were
>> "real" threads involved.
>
> No you don't.  Try this example - think about running the same shell
> script twice, but concurrently.  Exactly the same code (the shell
> script interpreter), but not necessarily thread-safe.  Try running two
> copies of the mysql cli - same code, but also not thread-safe.  You
> can
> fork() any number of processes using the same code without ever
> needing
> to worry about thread safety.

That's funny.

I worry about running two copies of the same PHP script in Apache
child processes and not having them tromp on each other's work...

You may not call this "thread safety" but it smells like the same
animal to me...

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux