Consider an application that waits for an incoming socket connection. Typically the function call to accept the connection blocks. Just in case 'blocks' isn't clear, it basically means the function will not return until some condition is met. In this case the function would not return until an incoming connection is established or until some other thread closed the server socket, both of which could be indefinite. If your application just had the one thread to accept the connection then you could never do anything else. Now introduce another thread. This new thread could close the server socket after a timeout or as the result of a button press (physical or graphical), etc.
----- Original Message ----- From: Knowledge Seeker To: [email protected] Sent: Thursday, April 01, 2010 11:39 PM Subject: [c-prog] MultiThreading !?! Hi, It might be a noob question, but still... would like know. "When do one decide that that he needs a thread". One usually describes producer-consumer example in multi threading. But producer-consumer can still happen in single thread like: // pseudo-code main() { int info[10]; producer(); //fills info consumer(); //empties info } or main() { producer(); } producer() { int info[10]; // do some processing to fill info-array consumer(info); } But in what scenario one decides that we need producer() and consumer() to run in separate threads. We all know that consumer() anyhow has to wait for info to be filled in producer(), whether it is single-threaded or multi-threaded. Thanks. Knowledge Seeker [Non-text portions of this message have been removed]
