[英]Is boost::asio::thread_pool thread safe when posting tasks on multiple threads?
I'm submitting more than one tasks to boost::asio::thread_pool concurrently.我同时向 boost::asio::thread_pool 提交了多个任务。 But official document does not talk about thread safe of boost::asio::thread_pool.
但是官方文档并没有讲到 boost::asio::thread_pool 的线程安全。
the boost lib version is 1.69. boost lib 版本是 1.69。 And my code like below:
我的代码如下:
/*define a thread pool*/
boost::asio::thread_pool pool(4);
//on thread 1
boost::asio::post(pool, my_task_1);
...
//on thread 2
boost::asio::post(pool, my_task_2);
so I want to know is the code able to work on multiple threads所以我想知道代码是否能够在多个线程上工作
boost::asio::post
uses executor to post tasks into thread pool. boost::asio::post
使用 executor 将任务发布到线程池中。 Executor requirements are described under this link . 此链接下描述了执行者要求。 One of sentences is
句子之一是
The executor copy constructor, comparison operators, and other member functions defined in these requirements shall not introduce data races as a result of concurrent calls to those functions from different threads.
这些要求中定义的执行器复制构造函数、比较运算符和其他成员函数不应由于从不同线程并发调用这些函数而引入数据竞争。
so your code is safe, you can call post
from multiple threads.所以你的代码是安全的,你可以从多个线程调用
post
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.