Boost logo

Boost Users :

From: Tim Day (timday_at_[hidden])
Date: 2007-10-22 14:25:08


On Mon, 2007-10-22 at 09:51 +0100, Apostolos Apostolidis wrote:
> Hi all. I have developed some code allowing a thread group of 500
> threads to run. However, as soon as the 381st thread is spawned,
> I get the following runtime error :
>
> terminate called after throwing an instance of
> 'boost::thread_resource_error'
> what(): boost::thread_resource_error

That's a lot of threads. For both win32 threading and Posix pthreads I
have an idea each thread consumes at least a megabyte of address space
and who knows what other limited resources. How much memory do you
have ?

Generally you want to structure your apps so that there is some
reasonable number of active "compute" threads (where "reasonable" is
some number not much higher than the number of CPU cores you have) and
so that the number of "I/O threads" (anything expected to make a
blocking call on an external service or device) is kept under control
too. Tools you might use to do this include mutex-protected queues of
work items being fed to the compute threads, and boost::asio.

Spawning 100s of threads is a fun thing to do, but it's not a very
efficient use of resources, and the OSes aren't really expecting anyone
to do it.

Have fun
Tim

[Of course, if you are actually developing on some monster machine with
100s of cores, please ignore the above!]


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