Page 1 of 1
Threads and the like
Posted: Wed Jan 03, 2007 5:03 pm
by RobertGonzalez
Ok, in response to my apparent lack of knowledge of servers and such, would anyone be willing to take a moment to explain to me what threads are, why PHP in some cases is not thread-safe and what the differences between a thread and a process are? I am certain I should know this well by now, but I don't (there, I said it, I admitted it, I don't know my shizzle) so any thoughts and opinions would be much appreciated in the 'Education of Everah Event'.
Posted: Wed Jan 03, 2007 5:21 pm
by feyd
A process is simply an instance of an executable. Threads are created by processes; basically sub-processes. Fibers are created by threads; basically sub-sub-processes.
I hope that was confusing enough.

Posted: Wed Jan 03, 2007 5:26 pm
by Kieran Huggins
Is "lint" simply a collection of zombie sub-sub-processes? 'Cause I get that!
Thread-safety:
http://en.wikipedia.org/wiki/Thread-safety
Posted: Wed Jan 03, 2007 5:37 pm
by feyd
Fibers terminate when their thread terminates. Threads terminate when their process terminates.
Posted: Wed Jan 03, 2007 5:39 pm
by RobertGonzalez
So Apache for example runs as an instance, which spawns a process which spawn threads (that is if I understand this correctly). So it is feasible to have an instance with many processes, and within each process, have many threads?
/ dablabit wikipedia. It seems to not want to let me into the door today.
Posted: Wed Jan 03, 2007 5:40 pm
by Weirdan
Wikipedia wrote:
Threads are distinguished from traditional multi-tasking operating system processes in that processes are typically independent, carry considerable state information, have separate address spaces, and interact only through system-provided inter-process communication mechanisms. Multiple threads, on the other hand, typically share the state information of a single process, and share memory and other resources directly. Context switching between threads in the same process is typically faster than context switching between processes. Systems like Windows NT and OS/2 are said to have "cheap" threads and "expensive" processes; in other operating systems there is not so great a difference.
Posted: Wed Jan 03, 2007 5:43 pm
by feyd
Apache runs under two processes and many threads every time I've checked.
Posted: Wed Jan 03, 2007 5:45 pm
by Weirdan
feyd wrote:Apache runs under two processes and many threads every time I've checked.
Unless configured to use prefork mpm or it is Apache 1.3.x

Posted: Wed Jan 03, 2007 6:11 pm
by RobertGonzalez
So at what point then does PHP become not thread-safe? For some reason I am having a really hard time wrapping my noodle around this concept.