pfoe
October 23, 2014, 7:09pm
1
I have a problem with a standalone threaded application. The system is
Linux 3.7.10-1.1-desktop, openSUSE 12.3 (Darthmouth) (x86_64) with
ROOT 5.34/21 (v5-34-21@v5-34-21, Sep 09 2014, 15:29:00 on linuxx8664gcc)
The application runs well, but if I do some interactions in the GUI (e.g. resize statistics panel) it crashes.
Here is the minimal example
#include <stdio.h>
//X11
//#include <X11/Xlib.h>
// ROOT
#include <TApplication.h>
#include <TThread.h>
#include <TCanvas.h>
#include <TH1S.h>
void *application(void *arg);
TThread* thread;
TCanvas* c;
TH1S* hist;
int main(int argc, char** argv)
{
//XInitThreads();
TApplication theApp("App", &argc, argv);
TThread::Lock();
c = new TCanvas("c", "TEST", 600, 400);
hist = new TH1S("h","Hist",4,0,3);
thread = new TThread("application",application,NULL);
thread->Run();
TThread::UnLock();
theApp.Run();
return 0;
}
void *application(void *arg)
{
printf("run in thread...\n");
while(1)
{
TThread::Lock();
hist->Fill((unsigned short)2);
c->cd();
hist->Draw("hists");
c->Modified();
//c->Update();
TThread::UnLock();
TThread::Sleep(1);
}
}
This code was also tested on windows an it crashes too.
and here is the output…
run in thread…
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
Thread 2 (Thread 0x7f8a62642700 (LWP 24788)):
#0 0x00007f8a669fb623 in select () from /lib64/libc.so.6
#1 0x00007f8a6b962b79 in TUnixSystem::Sleep(unsigned int) () from /usr/local/lib/root/libCore.so
#2 0x00007f8a67c5df79 in TThread::Sleep(unsigned long, unsigned long) () from /usr/local/lib/root/libThread.so
#3 0x00000000004025e2 in application(void*) ()
#4 0x00007f8a67c5f000 in TThread::Function(void*) () from /usr/local/lib/root/libThread.so
#5 0x00007f8a66ccee0f in start_thread () from /lib64/libpthread.so.0
#6 0x00007f8a66a027dd in clone () from /lib64/libc.so.6
Thread 1 (Thread 0x7f8a6c27b100 (LWP 24781)):
#0 0x00007f8a669d31e7 in waitpid () from /lib64/libc.so.6
#1 0x00007f8a6695bb50 in do_system () from /lib64/libc.so.6
#2 0x00007f8a6695bf10 in system () from /lib64/libc.so.6
#3 0x00007f8a6b967af6 in TUnixSystem::StackTrace() () from /usr/local/lib/root/libCore.so
#4 0x00007f8a6b96a363 in TUnixSystem::DispatchSignals(ESignals) () from /usr/local/lib/root/libCore.so
#5
#6 0x00007f8a6938c827 in TCanvas::HandleInput(EEventType, int, int) () from /usr/local/lib/root/libGpad.so
#7 0x00007f8a643820bb in TRootCanvas::HandleContainerMotion(Event_t*) () from /usr/local/lib/root/libGui.so
#8 0x00007f8a6436c058 in TGFrame::HandleEvent(Event_t*) () from /usr/local/lib/root/libGui.so
#9 0x00007f8a643b0538 in TGClient::HandleEvent(Event_t*) () from /usr/local/lib/root/libGui.so
#10 0x00007f8a643b0645 in TGClient::ProcessOneEvent() () from /usr/local/lib/root/libGui.so
#11 0x00007f8a643b069d in TGClient::HandleInput() () from /usr/local/lib/root/libGui.so
#12 0x00007f8a6b96aa18 in TUnixSystem::DispatchOneEvent(bool) () from /usr/local/lib/root/libCore.so
#13 0x00007f8a6b8df126 in TSystem::InnerLoop() () from /usr/local/lib/root/libCore.so
#14 0x00007f8a6b8e0d14 in TSystem::Run() () from /usr/local/lib/root/libCore.so
#15 0x00007f8a6b9059df in TApplication::Run(bool) () from /usr/local/lib/root/libCore.so
#16 0x00000000004024a1 in main ()
The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
root.cern.ch/bugs . Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
#6 0x00007f8a6938c827 in TCanvas::HandleInput(EEventType, int, int) () from /usr/local/lib/root/libGpad.so
#7 0x00007f8a643820bb in TRootCanvas::HandleContainerMotion(Event_t*) () from /usr/local/lib/root/libGui.so
#8 0x00007f8a6436c058 in TGFrame::HandleEvent(Event_t*) () from /usr/local/lib/root/libGui.so
#9 0x00007f8a643b0538 in TGClient::HandleEvent(Event_t*) () from /usr/local/lib/root/libGui.so
#10 0x00007f8a643b0645 in TGClient::ProcessOneEvent() () from /usr/local/lib/root/libGui.so
#11 0x00007f8a643b069d in TGClient::HandleInput() () from /usr/local/lib/root/libGui.so
#12 0x00007f8a6b96aa18 in TUnixSystem::DispatchOneEvent(bool) () from /usr/local/lib/root/libCore.so
#13 0x00007f8a6b8df126 in TSystem::InnerLoop() () from /usr/local/lib/root/libCore.so
#14 0x00007f8a6b8e0d14 in TSystem::Run() () from /usr/local/lib/root/libCore.so
#15 0x00007f8a6b9059df in TApplication::Run(bool) () from /usr/local/lib/root/libCore.so
#16 0x00000000004024a1 in main ()
Error in : BadDrawable (invalid Pixmap or Window parameter) (XID: 23068891, XREQ: 62)
How do I handle threads in a standalone application properly?