On Thu, Sep 27, 2001 at 03:25:17AM +1000, Minh Van Le wrote: > Is multithreading more efficient than forks ? or there's no difference > under Linux ?
Simple question but my answer is not. For efficiency of writing code: Writing bug free multithreading code is a lot harder than process based (or forking with interprocess communication). For efficiency of running: I'm not sure what happens at the extremes, with say many thousands of forks or threads, or if startup latency is an issue. I imagine these would all depend on circumstances (e.g. if you preforked and exec'ed before you needed to you could save on latency at a crucial point). Another thing to consider is whether you have large amounts of shared data. If this is static then a fork will be fine, if constantly changing then threading may be more useful (you need to protect access though, which is where the more careful programming of threads comes in). One thing to be aware of if you are doing cross platform stuff (i.e. for Windows), they don't have a nice fork model (cygwin may have solved this by now), so you are virtually forced to use threads. As nice example of a cross platform thread library is in SDL (GPL'ed). With forking and IPC, you could later more easily use cluster programming, having complete systems doing parts of the work. There, probably more than you wanted to know or care. Hows this: if programming for Linux, use forking and IPC. You'll probably get your code written cleaner and quicker, and the running probably will be more than acceptable. Jamie -- SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug
