Description
As reported in boostorg/boost_install#27, the following program:
#include <boost/thread/condition_variable.hpp>
int main() {
boost::condition_variable cv;
boost::mutex mutex;
boost::unique_lock<boost::mutex> lock(mutex);
cv.wait_for(lock, boost::chrono::seconds(1));
return 0;
}
compiles on Linux but doesn't link without specifying -lboost_chrono
, even though the Boost.Thread build/Jamfile doesn't specify Chrono as a dependency on Pthread platforms. The reason is that the Jamfile defines BOOST_THREAD_DONT_USE_CHRONO
on Pthread platforms when Boost.Thread is built. However, when Boost.Thread is used by user code, BOOST_THREAD_DONT_USE_CHRONO
is not defined and https://github.com/boostorg/thread/blob/develop/include/boost/thread/detail/config.hpp#L143 defines BOOST_THREAD_USES_CHRONO
. This enables the wait_for
overload and allows the code above to compile, even though the compiled library wasn't built with BOOST_THREAD_USES_CHRONO
.
I'm not sure whether this behavior can be considered correct. One may argue that BOOST_THREAD_USES_CHRONO
should not be defined on Pthread platforms by default, to match the settings with which the library is built.