
Jonathan Franklin wrote:
On Mon, Mar 17, 2008 at 9:17 AM, Hal Vaughan
wrote: So when I did just a loop in a routine that printed numbers 1-10 (or, when I experimented, 1-1000), and thread 1 always finished completely before thread 2 could start, is that the same? Is there any way I can get the two threads to run concurrently?
Either give the threads more work to do (print *all* integers), or sleep for a second between each int.
... I was hoping there might be a way, in C++, to spin off this listener thread, let it keep listening and processing the data, and have it stay in the background so other threads can continue.
You can do this in C++ w/ practically any threading library.
I've tried with pthread and I have to specifically tell it to yield at some point or the other thread doesn't get a chance to do anything until the first thread is done. If you have any resources that can tell me how to do it, I'd really appreciate a few links or other info.
So is there no way to create a thread and not have it take up all the CPU time until it's done without using SMP?
Throw in a periodic nanosleep (or whatever) call if the worker thread is doing too much work. This will yield the processor to another thread or process.
That's a help. I hadn't heard of nanosleep at all. (Sometimes you miss a lot when you're teaching yourself!) Thanks! Hal