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

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

 



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).

> 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. 


/Per Jessen, Zürich

--
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