Opened 8 years ago
Closed 7 years ago
#11158 closed Bugs (fixed)
Pthread thread deadlock when faketime used
Reported by: | Owned by: | viboes | |
---|---|---|---|
Milestone: | Boost 1.60.0 | Component: | thread |
Version: | Boost 1.55.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Following code deadlocked on pthread_cond_timedwait call if started like
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1 FAKETIME="+30d" ./a.out
#include <boost/thread.hpp> #include <iostream> using namespace std; void f() { int n=50; while (n--) { cout << n << endl; boost::this_thread::sleep(boost::posix_time::seconds(1)); // boost::this_thread::sleep_for( boost::chrono::seconds(1) ); // sleep(1); } } int main(int argc, char* argv[]) { boost::thread th(f); th.join(); return 0; }
Here is backtarce:
#0 pthread_cond_timedwait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S:238 #1 0x0000000000da8ed3 in boost::condition_variable::do_wait_until(boost::unique_lock<boost::mutex>&, timespec const&) () #2 0x0000000000da792f in boost::this_thread::hiden::sleep_until(timespec const&) () #3 0x0000000000978ff6 in boost::this_thread::sleep (abs_time=...) at /home/sl/project/Elephantdrive/devroot/3rdparty/boost/boost/thread/pthread/thread_data.hpp:249 #4 0x0000000000979065 in boost::this_thread::sleep<boost::posix_time::seconds> (rel_time=...) at /home/sl/project/Elephantdrive/devroot/3rdparty/boost/boost/thread/pthread/thread_data.hpp:255
But no deadlocks if used sleep(1) instead. I belive it is some pthread_cond_timedwait issue but will be good call sleep() or usleep() in boost's internals instead in according points if possible.
Change History (5)
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 7 years ago
I've a patch that uses pthread_condattr_setclock. I have no platform providing it (I'm using MacOS). The user will need to define BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC until I find a way to detect it.
can you check if this works for you?
Add to develop branch https://github.com/boostorg/thread/commit/9f883f6ad7377b88b79fa70cc5de68cbfb0213e4
comment:4 by , 7 years ago
Milestone: | To Be Determined → Boost 1.60.0 |
---|
comment:5 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Can you use
which is not interruptible and so don't need the use of cv?