|
Boost Users : |
From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2006-10-12 07:16:26
Prashant Thakre wrote:
> On Windows the ~thread() doesnot detach the thread. Hence, the below listed
> code will throw boost::thread_resource_error().
... <example snipped> ...
What do you expect? You cant simply create threads beyond the
system limits, which is roughly 2000 on my box.
I tried your code with a really short lived thread:
by using function void f() {}.
This runs "forever". When running in a debugger, then setting
a breakpoint, you will see no threads beyond the main running.
When changing f to
void f() { Sleep(100000); }
however the resource exception will be thrown when the system
runs out of resources, which happend around 2000 in my case.
BTW.: There might be a misconception about the usage of threads.
One normally wouldn't like to pay the cost of starting up a thread
for short lived tasks. Instead you would create a queue of jobs
that have to be done, and a pool (of fixed size) of threads, which
pick a job from the queue. When done they pick the next one, without
shuting down the thread in meantime. When the queue is empty, the
thread will not stop, but wait on a condition variable signalling
that more work is available.
I agree that it would be nice if such a jobs queue would be available
in boost. But this doesn't strictly belong to boost::threads.
This is kind of an abstraction that should be built on top of boost
threads.
Roland
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net