I am developing a standalone CMake program that makes use of a TApplication to show a couple of GUI windows with some internal TThreads and TTimers. I call ROOT::EnableThreadSafety in the very beginning.
However, sometimes, when stopping the TThread, my program freezes. When running it through the debugger, I see the following (below).
Is there any way I can prevent this freeze? Note: RThread is a TThread derived class, following How to Use the ROOT TThread, that calls TThread::Printf() when stopped. Maybe I should avoid calling Printf ?
Thread 1:
1 futex_wait_cancelable futex-internal.h 183 0x7ffff7482376
2 __pthread_cond_wait_common pthread_cond_wait.c 508 0x7ffff7482376
3 __pthread_cond_wait pthread_cond_wait.c 638 0x7ffff7482376
4 std::condition_variable::wait(std::unique_lock<std::mutex>&) 0x7ffff7361e50
5 ROOT::TReentrantRWLock<std::mutex, ROOT::Internal::RecurseCountsTBBUnique>::ReadLock() 0x7ffff685d125
6 THashTable::FindObject(const char *) const 0x7ffff7713bad
7 TClass::GetClass(const char *, bool, bool, unsigned long, unsigned long) 0x7ffff776305a
8 TClass::InheritsFrom(const char *) const 0x7ffff77641f5
9 TGCommandPlugin::CheckRemote(const char *) 0x7ffff7c84655
10 TGCommandPlugin::HandleTimer(TTimer *) 0x7ffff7c84880
11 TTimer::Notify() 0x7ffff76e5d06
12 TTimer::CheckTimer(TTime const&) 0x7ffff76e5749
13 TUnixSystem::DispatchTimers(bool) 0x7ffff77c1eaf
14 TUnixSystem::DispatchOneEvent(bool) 0x7ffff77c2e1d
15 TSystem::Run() 0x7ffff76cfa49
16 TApplication::Run(bool) 0x7ffff76674e3
17 main main.cxx 121 0x55555555f315
Thread 2:
1 __GI___poll poll.c 29 0x7ffff7048aff
2 ?? 0x7fffdfd831a2
3 start_thread pthread_create.c 477 0x7ffff747b609
4 clone clone.S 95 0x7ffff7055293
Thread 3:
1 futex_wait_cancelable futex-internal.h 183 0x7ffff7482376
2 __pthread_cond_wait_common pthread_cond_wait.c 508 0x7ffff7482376
3 __pthread_cond_wait pthread_cond_wait.c 638 0x7ffff7482376
4 TThread::XARequest(const char *, int, void * *, int *) 0x7ffff686cc6a
5 TThread::Printf(const char *, ...) 0x7ffff686ce49
6 RThread::Stop RThread.cpp 118 0x7ffff7f263bb
7 MainWindow::DoStopDAQ MainWindow.cpp 1720 0x7ffff7f3a5ee
8 MainWindow::SaveAndExit MainWindow.cpp 1206 0x7ffff7f37156
9 ?? 0x7fff9ec2702a
10 ??
In other cases, the problem comes from another TTimer I use specifically, not the internal one in TGCommandPlugin. Here the gdb output:
Thread 1 "runGUI" received signal SIGINT, Interrupt.
futex_wait_cancelable (private=<optimized out>, expected=0, futex_word=0x555556ccb85c) at ../sysdeps/nptl/futex-internal.h:183
183 ../sysdeps/nptl/futex-internal.h: No such file or directory.
(gdb) thread apply all bt
Thread 3 (Thread 0x7ffedf519700 (LWP 417864)):
#0 futex_wait_cancelable (private=<optimized out>, expected=0, futex_word=0x555557d50f9c) at ../sysdeps/nptl/futex-internal.h:183
#1 __pthread_cond_wait_common (abstime=0x0, clockid=0, mutex=0x5555568b8a80, cond=0x555557d50f70) at pthread_cond_wait.c:508
#2 __pthread_cond_wait (cond=0x555557d50f70, mutex=0x5555568b8a80) at pthread_cond_wait.c:638
#3 0x00007ffff686cc6a in TThread::XARequest(char const*, int, void**, int*) () from /opt/root/lib/libThread.so
#4 0x00007ffff686ce49 in TThread::Printf(char const*, ...) () from /opt/root/lib/libThread.so
#5 0x00007ffff7f26390 in RThread::Stop (this=0x5555573de458) at /home/user/zdt-daq/gui/RThread.cpp:117
#6 0x00007ffff7f3a561 in MainWindow::DoStopDAQ (this=0x7ffffffdd380) at /home/ferhue/zdt-daq/gui/MainWindow.cpp:1715
#7 0x00007ffff7f37156 in MainWindow::SaveAndExit (this=0x7ffffffdd380) at /home/ferhue/zdt-daq/gui/MainWindow.cpp:1206
#8 0x00007ffedec5502a in ?? ()
#9 0x0000000000000000 in ?? ()
Thread 2 (Thread 0x7fffdfd44700 (LWP 417863)):
#0 0x00007ffff7048aff in __GI___poll (fds=0x7fffdfd3ea80, nfds=2, timeout=-1) at ../sysdeps/unix/sysv/linux/poll.c:29
#1 0x00007fffdfd831a2 in ?? () from /lib/x86_64-linux-gnu/libusb-1.0.so.0
#2 0x00007ffff747b609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#3 0x00007ffff7055293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
Thread 1 (Thread 0x7ffff521cb80 (LWP 417832)):
#0 futex_wait_cancelable (private=<optimized out>, expected=0, futex_word=0x555556ccb85c) at ../sysdeps/nptl/futex-internal.h:183
#1 __pthread_cond_wait_common (abstime=0x0, clockid=0, mutex=0x5555567aa760, cond=0x555556ccb830) at pthread_cond_wait.c:508
#2 __pthread_cond_wait (cond=0x555556ccb830, mutex=0x5555567aa760) at pthread_cond_wait.c:638
#3 0x00007ffff7361e50 in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff685c3a6 in ROOT::TReentrantRWLock<std::mutex, ROOT::Internal::RecurseCountsTBBUnique>::WriteLock() () from /opt/root/lib/libThread.so
#5 0x00007ffff76b03ea in TQConnection::LockSlot() const () from /opt/root/lib/libCore.so
#6 0x00007ffff7cc92a7 in TQConnection::SendSignal() () from /opt/root/lib/libGui.so
#7 0x00007ffff7f285ec in TQObject::EmitVA<>(char const*, int) (this=0x7ffffffdd6d0, signal_name=0x7ffff7928d53 "Timeout()") at /home/ferhue/builds/build-root_src-Desktop-Debug/include/TQObject.h:137
#8 0x00007ffff76e5cf1 in TTimer::Notify() () from /opt/root/lib/libCore.so
#9 0x00007ffff76e5749 in TTimer::CheckTimer(TTime const&) () from /opt/root/lib/libCore.so
#10 0x00007ffff77c1eaf in TUnixSystem::DispatchTimers(bool) () from /opt/root/lib/libCore.so
#11 0x00007ffff77c2e1d in TUnixSystem::DispatchOneEvent(bool) () from /opt/root/lib/libCore.so
#12 0x00007ffff76cfa49 in TSystem::Run() () from /opt/root/lib/libCore.so
#13 0x00007ffff76674e3 in TApplication::Run(bool) () from /opt/root/lib/libCore.so
#14 0x000055555556b315 in main (argc=3, argv=0x7fffffffe118) at /home/ferhue/zdt-daq/gui/main.cxx:121
If I remove the TThread::Printf() part from my Stop() function, then it does not freeze. Is there a better way to issue this Printf so that it does not cause a freeze?
ROOT Version: 6.25/01
Platform: Ubuntu 20
Compiler: gcc