我可以使用c ++中的boost生成多少个线程?

jon*_*rry 8 c++ concurrency multithreading boost

当我尝试产生太多时会发生什么?

当我产生超过900个线程时,我收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

这是因为尝试生成太多线程而导致的预期错误吗?

Mic*_*eyn 9

请记住,每个线程都需要保留堆栈空间.这就是为什么可以产生的线程数量有限制的原因.看起来你要么达到这个限制,要么提升阻止你达到这个限制.

以下是最新的boost文档的链接,它记录了您所看到的行为(抛出的异常):boost thread docs(在该页面上搜索boost :: thread_resource_error)