Threads and the like

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Threads and the like

Post 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'.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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. :)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Fibers terminate when their thread terminates. Threads terminate when their process terminates.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Apache runs under two processes and many threads every time I've checked.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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 :)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

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