I have a code base that is using many instances of detached boost::thread as folllows
boost::thread th( boost::bind(&myFunc,var1, var2 ));
Can I simply do a search replace and start using std::thread?
Do I need to replace boost::bind with std::bind too or that is unnecessary?
( I found I could do search replace boost::shared_ptr with std::shared_ptr and boost::scoped_ptr with std::unique_ptr so far without any issues.
My platform is Visual Studio 11 on Windows 7.
The current version of
boost::threadhas a few features that aren’t instd::thread:yield()andsleep()(deprecated)See the boost documentation, where they are labelled
EXTENSION. If you’re not using any of those, then it should be a direct replacement.As mentioned in the comments, older versions of
boost::threadhad a different behaviour on destruction. They would detach the thread if it was still joinable;std::threadand the currentboost::threadcallstd::terminateinstead.That’s not necessary;
threadcan be given any callable type. It’s also not necessary to usebindat all, since it has a variadic constructor: