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

From: Date: Thu, 31 Jan 2008 07:40:52 +0000
Subject: Re: Re: how do you get to do multiple mysql queries concurrently?
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  Groups: php.general 
Request: Send a blank email to php-general+get-268419@lists.php.net to get a copy of this message
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

« previous php.general (#268419) next »