我注意到boost :: asio :: threadpool不会将诸如浮点环境之类的线程本地状态复制到子线程中。这在我的应用程序中引起了细微的错误。我当前的解决方案是对发布到线程池的每个任务进行调用fesetenv。
所以我当前的工作流程是
boost::asio::thread_pool m_threadPool;
fenv_t curr_env;
/* Save current environment. */
fegetenv(&curr_env);
/* Post tasks to the threadpool but set the fp environment before doing the real work */
boost::asio::post(m_threadPool,[&](){
fesetenv(&curr_env);
task();
});
即使 fesetenv 可能很快,我还是希望池中的每个线程都运行一次。有什么办法吗?