Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: SecretShop on March 29, 2006, 01:37 PM

Title: Threads, when to use and why?
Post by: SecretShop on March 29, 2006, 01:37 PM
Heres a question, when writing a few programs I have been presented with the choice to use or not use threads.  Every time I usually choose not to and just multi-plex with some async calls.  Under what circumstances is it better or worse to use threads and why? What do you guys think?
Title: Re: Threads, when to use and why?
Post by: Yoni on April 06, 2006, 01:49 PM
On multiprocessor systems, if you run 1 thread per CPU, you utilize all CPUs.
Title: Re: Threads, when to use and why?
Post by: MyndFyre on April 06, 2006, 01:54 PM
Quote from: SecretShop on March 29, 2006, 01:37 PM
Heres a question, when writing a few programs I have been presented with the choice to use or not use threads.  Every time I usually choose not to and just multi-plex with some async calls.  Under what circumstances is it better or worse to use threads and why? What do you guys think?

When you need to do a background task and not interrupt the GUI.  (This is common for print spooling or listening for data over the network).
Title: Re: Threads, when to use and why?
Post by: Banana fanna fo fanna on April 06, 2006, 02:24 PM
Use non-blocking calls whenever possible (i.e. I/O) and IPC or threads when you need.

OT: does anyone know a Scheme implementation with nonblocking I/O?
Title: Re: Threads, when to use and why?
Post by: Yegg on April 06, 2006, 02:45 PM
Quote from: Banana fanna fo fanna on April 06, 2006, 02:24 PM
OT: does anyone know a Scheme implementation with nonblocking I/O?

Depending on what you're intersted in, have you tried CHICKEN? If you don't already know about it, it can easily interface with C.