Breaking changes in Boost.Thread 3.0.0

强颜欢笑 提交于 2019-12-01 15:11:11

问题


In the release notes of version 1.50.0 of the Boost libraries I noted two breaking changes (see here):

#6266 Breaking change: thread destructor should call terminate if joinable.

#6269 Breaking change: thread move assignment should call terminate if joinable.

What does this mean for my existing projects currently using Boost 1.49.0? Do I have to change anything? If yes, what do I have to change exactly? And what happens if I forget to modify one of my existing projects? Will I get compile time errors (I hope so) or will I get nasty and hard-to-find runtime problems (I absolutely don't hope so)?


回答1:


When it says "Breaking change", it means, "Your program is broken if you depend on behaviour which was previously X, but is now Y".

For the given two changes, it means that if you rely on the destructor or move assignment calling join() (or detach()), which I believe was the previous behaviour, your program must now explicitly join() or detach() or meet your friend std::terminate(). It's not a compile-time error, but nor is it unpredictable run-time behaviour- you'll get a nice clean crash leading right back to boost::thread's destructor, which is the cause of the problem.




回答2:


The following code used to work correctly, but with v3 the program would be aborted as t leaves its scope, because thread::~thread calls std::terminate, instead of silently detaching from the thread:

#include <boost/thread.hpp> 
#include <iostream>

void f()
{}

int main() 
{ 
  {
    boost::thread t(f);
  }
  std::cout << "exiting gracefully" << std::endl;
} 


来源:https://stackoverflow.com/questions/11393936/breaking-changes-in-boost-thread-3-0-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!