And what happens when I try to spawn too many?
I'm getting the following error when I spawn more than about 900 threads:
terminate called after throwing an instance of 'dining 1
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::thread_resource_error>
>dining 3
'
dining 2
what(): dining 4
boost::thread_resource_errordining 3
Is this the expected error resulting from attempting to spawn too many threads?
Remember that each thread needs to reserve stack space. That is why there is a limit on the number of threads you can spawn. It looks like you are either hitting this limit or boost is stopping you from hitting this limit.
Here is a link to the most recent boost documentation that documents the behavior you are seeing (the exception thrown): boost thread docs (search for boost::thread_resource_error on that page)
How many you can spawn depends on the constraints of your operating environment. And yes, boost::thread_resource_error
is what you should expect when it cannot get the proper thread resources it needs, per the documentation
You are hitting a hard limit. As others have said there can be two limitations:
Incidentally, this is what is so interesting about Google Go routines. Instead of spawning as much thread as possible, the Go runtime will adapt the number of threads to the number of cores available, and manually multiplex the routines on these physical threads.
Furthermore, the routines are lightweight (reserving only 4 KB each) because they don't use a traditional stack (disappearance of the Stack Overflow !), meaning that you can effectively span a few thousands routines on a typical machine and it won't cost you much.
If you wish to experiment with extreme parallelism:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With