TQObject 'signal' from TThread cause GUI crash

Root 5.34/10 … Sep 04 2013 on linux
$ cat /proc/version
Linux version 2.6.32-358.23.2.el6.i686 (mockbuild@c6b9.bsys.dev.centos.org)
(gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) ) #1 SMP Wed Oct 16 17:21:31 UTC 2013

I am trying to emit a signal from a thread.
On doing this the program hangs.

I have made a smaller version of my program to show the error.
The executable generated is “ex13app”
I have included the ‘Makefile’
first extract the files in a test directory, then
do ‘make dict’ then do ‘make’ to generate executable file.

I have searched the forums for a solution and came upon the following:
‘TQObject ‘signal’ from TThread cause GUI carsh’
by handong fri Sep 07, 2012 16:29
So I adopted the same topic heading.
In this particular post mentioned above , the problem occured in
Windows 32 software, and a solution using a Timer message is proposed.
I have got the similar problem under linux CentOS ver 6.4 32 bit.
Help greatly appreciated. Thanks.
ex13.tar (10 KB)

Part of code is displayed below, if this is of any help.

MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h)
: TGMainFrame(p,w,h) {


mTh = 0;

mTh= new TThread(“memberfunction”,(void(*)(void ))&MyMainFrame::Thread0,(void) this);

// mTh->Connect(“DoDraw()”,“MyMainFrame”,this,“DoDraw()”);

TQObject::Connect(“DoDraw()”,“MyMainFrame”,this,“DoDraw()”);

// Create a TTimer (timer called every 1000 msec)
timer = new TTimer();
timer->Connect(“Timeout()”, “MyMainFrame”,
this, “DoDraw()”);


}


//*********************************
void* MyMainFrame::Thread0(void* arg)
{
while ( (stopbpressed == kFALSE) & ( i < 110))
{
printf(“In thread Thread0 loop , i = %d \n”,i);
TThread::Lock();
i++;
TThread::UnLock();

if ( i == 105) {
i = 108;
Emit("DoDraw()");   // the code hangs after this line


Hi,

OK, so first of all, I don’t understand why you are trying to use a timer, connected to the DoDraw() method, the same method that you try to “emit” in your thread (and this “DoDraw()” method is not declared as a signal, BTW…).
So instead of spending time trying to understand what you’re trying to do, here is a simple example of a GUI application with a thread filling and updating an histogram. Hope this will help.

Cheers, Bertrand.
ex14.tar.gz (2.32 KB)

Thanks for looking at my code.
ok , I missed the comment //SIGNAL to declare “DoDraw()” as a SIGNAL.
even with it the behavoiur of the code is same.
I downloaded and tried to compile your program “ex14” without success.
Error messages are coming.
I looked at your code in ex14. In this code, in the thread you are
filling and updating a histogram in a thread.
Initially I had the following problem with my code,
in my DAQ application the data filling part of the code takes a
fixed amount of time specified in a widget Numberentry box in the GUI.
It can be as short as 1 second …or 10 seconds or 20000 seconds.
I had two buttons in mu GUI - one ‘START’ and the other 'STOP’
If I put the data filling and updating part in the OnStartbuttonpressed()
code , then the code used to run and generate the data files , but I could
not enable the ‘STOP’ button and disable the ‘START’ button.
Your program seems to address this problem , but in my approach I tried to
do this thing a little differently. I put the data filling part in a thread,
and tried to get a slot-method in the main program do the updating of the data
displayed by trying to emit a signal from the thread, when a part of the data
was ready for display. This is what I tried to replicate in ‘ex13’- trying
to emit a signal from a thread to run a method in the main program - but
this causes the program to hangup.
Your program structure looks good, and I will try to implement it,
before that kindly comment on the method I was trying to implement
as described above. Thank you very much for all your help.
Regards,
ABRAHAM

Hi ABRAHAM,

[quote=“Abyroot2014”]I downloaded and tried to compile your program “ex14” without success.
Error messages are coming.[/quote]What kind of messages? Could you be more precise?
And as far as I know, you cannot use signal slots across different threads. So you should use another method to implement what you need.

Cheers, Bertrand.

And here is the same example, but with a timer updating the canvas every second.

ex14b.tar.gz (2.35 KB)
Cheers, Bertrand.

[quote=“bellenot”]Hi ABRAHAM,

[quote=“Abyroot2014”]I downloaded and tried to compile your program “ex14” without success.
Error messages are coming.[/quote][/quote]What kind of messages? Could you be more precise?

Error messages in attached text file.
Thanks.
Regards,
Abraham
forum email5.txt (10.6 KB)

OK, please correct the Makefile (I was using $(ROOTSYS) instead of your hardcoded path), or properly set ROOTSYS and PATH in your terminal session (e.g. by sourcing root/bin/thisroot.sh)…

Cheers, Bertrand.

Thank you Bertrand.
I changed the ‘Makefile’ now the code compiles and runs.
and thanks for the take away lesson
" you cannot use signal slots across different threads. So you should use another method to implement what you need."
I will modify my code according to your example.
Thanks for solving my question.
Regards,
ABRAHAM

You’re very welcome! And don’t forget to take a look at the ex14b.tar.gz example!

Cheers, Bertrand.