On Mon, Jun 02, 2003 at 11:59:22AM +0100, Alex Hudson wrote: > On Mon, Jun 02, 2003 at 05:48:22AM -0500, Nigel Hamilton wrote: > > > I suspect i get called heretical for this, but I actually prefer to use > > > threads when it comes to these things. > > > a) better memory efficiency > > > b) easier and more advanced control over queueing and message handling > > > c) added bonus for you - no more reaping! :) > > > > a + b + c = sounds great. > > I'm not sure how big a win threads would be in this instance, if any. Most > threading libraries are fork()-based anyway - Linux doesn't have 'threads' > natively, but a very fast fork() implementation. (Solaris does have threads > I believe, not sure about the BSDs).
Umm.. Not really. Threads are like fork(), only without the copy/copy-on-write stuff, and everything else in fact. The process table is duplicated, sharing the same memory space, file descriptors, shared libs, and so forth. Creating a new thread under linux is a very fast operation, and task switching between threads is also very fast - check out the code in the kernel to see just how little has to be done. When you have a lot of processes, you save on task-switching if they are all threads instead of forked copies. Since you save a lot of memory, you can run a lot more concurrently than you would if you were using forked processes. Because creating/deleting threads doesn't involve mass memory operations, the operations are quicker. tjc