I'm having a problem troubleshooting a deadlock. I have a main thread which runs "reports" using a pool of worker threads. I'm using std:: mutex and condition_variable_any to control the synchronisation. Running on intel 64 bit linux. gcc 7.1
// main thread
void application_server::get_reports(){
...
std::recursive_mutex report_state_mutex;
std::condition_variable_any report_notification;
...
...
std::unique_lock<std::recursive_mutex> lock(report_state_mutex);
report_notification.wait(lock, [&] {
return std::all_of(report_list.begin(), report_list.end(), [](const multi_report_part_ptr& ptr) { return ptr->is_completed(); });
});
...
...
// child threads
bool multi_report_part::try_to_start() {
run();
// _mutex is a reference to report_state_mutex
std::unique_lock<std::recursive_mutex> lock(_mutex);
_finished = true;
lock.unlock();
// _notification is a reference to report_notification
_notification.notify_one();
return true;
}
gdb shows one child thread is blocked inside notify_one. Any ideas how this could be possible?
Thread 14 (Thread 0x7f613f3ff700 (LWP 56961)):
#0 0x00007f615d5ad6d5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1 0x00007f615b993d5c in __gthread_cond_wait (__mutex=<optimized out>, __cond=__cond@entry=0x7f613f3fce00) at /apps/nexus/http/tmp/gcc_build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu/bits/gthr-default.h:864
#2 std::condition_variable::wait (this=this@entry=0x7f613f3fce00, __lock=...) at ../../../../../gcc-7.1.0/libstdc++-v3/src/c++11/condition_variable.cc:53
#3 0x00000000004bc2a4 in wait (__lock=..., this=0x7f613f3fce00) at /apps/nexus/local/GCC620/include/c++/6.2.0/condition_variable:251
#4 wait (__p=..., __lock=..., this=0x7f613f3fce00) at /apps/nexus/local/GCC620/include/c++/6.2.0/condition_variable:260
#5 get_reports (this=this@entry=0x7f615a1fa810, response=..., args=..., func_name=func_name@entry=0x6ad953 <tcpip::application_server...
Thread 10 (Thread 0x7f61453ff700 (LWP 56956)):
#0 0x00007f615d5b01bd in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007f615d5abd02 in _L_lock_791 () from /lib64/libpthread.so.0
#2 0x00007f615d5abc08 in pthread_mutex_lock () from /lib64/libpthread.so.0
#3 0x000000000046a303 in __gthread_mutex_lock () at /apps/nexus/local/GCC620/include/c++/6.2.0/x86_64-pc-linux-gnu/bits/gthr-default.h:748
#4 std::mutex::lock() (this=<optimized out>) at /apps/nexus/local/GCC620/include/c++/6.2.0/bits/std_mutex.h:103
#5 0x0000000000527207 in std::lock_guard<std::mutex>::lock_guard(std::mutex&) () at /apps/nexus/local/GCC620/include/c++/6.2.0/bits/std_mutex.h:162
#6 notify_one (this=0x7f6143bfce00) at /apps/nexus/local/GCC620/include/c++/6.2.0/condition_variable:230
#7 try_to_start (this=<optimized out>) at ../../src/adder/multi_report_part.cpp:17
Aucun commentaire:
Enregistrer un commentaire