16 Mar
2010
16 Mar
'10
7:19 p.m.
On 3/16/10 6:44 PM +0200 Timo Sirainen wrote:
Threads are useful when you need to do CPU intensive work in parallel, and threads need access to shared data structures.
And when you don't want to block on I/O. Threads are almost always easier than AIO, and especially easy (ie, no scary complexity issues eg deadlock) if you aren't sharing data structures.
It used to be that threads weren't scheduled well, and that if you wanted Linux portability you should avoid them, but in the last 5 years that has changed and usu. it's the best choice now.
You mentioned locking overhead earlier, which is a red herring, but even on Linux if you are running an SMP kernel you have the locking "overhead" even if your process is single threaded.
-frank