2 ms·
> On modern OS's, don't threads generally start up quicker and take less memory than processes? Yes... but the thing is, that's largely as a function of sharin
by MaulingMonkey 12y ago
> On modern OS's, don't threads generally start up quicker and take less memory than processes?
Yes... but the thing is, that's largely as a function of sharing data!
The OS can skip image relocation for the executable and it's dynamic libraries by sharing the same data with the other threads of the process. Process metadata is shared, so no new process entries need be created.
Your program can skip the parsing of configuration files, command line arguments, and other initialization by sharing the same data already parsed read and initialized by the other threads of the process.
On some platforms, there's fork(), which lets you retain some of the advantages of shared data. Not all of them: For example, one of the tradeoffs of a compacting garbage collector is that the relocation of data can cause those pages to become no longer shared between the forked processes, even if the data on those pages was otherwise untouched and identical, because the compacting isn't shared between processes.
The general trick is to keep a pool of processes ready to handle work, much as efficient thread pools avoid spinning up new threads for every tasklet.