TThread and c-function

Hi,

I am trying to use TThread to run a c-function.

I used to do:

int Connect2TWS::ThreadStart( tws_func_t func, void *arg ) {
pthread_t thr ;
int err = pthread_create(&thr, 0, (void ()(void *)) func, arg) ;
return err ;
}

and replaced it with what I would naively expect to be correct:

int Connect2TWS::ThreadStart( tws_func_t func, void *arg ) {
TThread thr = new TThread( (void() (void *)) func, arg) ;
int err = thr->Run() ;
return err ;
}

In ROOT I now get:

root [2] bla->AddConnection()
tws reader thread started
tws reader thread terminated
root [3]

Instead of the previous:

root [2] bla->AddConnection()
tws reader thread started
root [3]

So, the TThread starts and stops immediately, where the pthread keeps on running. Am I missing something trivial? Under the hood, TThread is simply calling pthread, isn’t it?

Thanks for your assistance,
Sander Klous

Hi Sander,

this should work fine. What is hapening in your user function? Mail me an small example.

Cheers, Fons.

Hi Fons,

I attached the debugger to shed some light on this subject.
Apparently, if I put a breakpoint on any of the lines between

if (!ierr) th->fId = (Long_t) id ;

in TPosixThread.cxx and

SetComment() ;

in TThread.cxx, the code runs fine. Outside of this region, breakpoints have no effect whatsoever. Based on this observation, I doubt if I am able to provide a small example. For the moment I’ll move back to the pthread code…

Thanks,
Sander

Hoi Sander,

any change I can try to debug this in the complete program, or is that the whole of ATLAS?

– Fons

Hi,
I tried to reproduce this problem on linux, but all works fine there.
So probably it is a gcc-cygwin only problem…

Still strange that it doesn’t show up when I use pthread directly.
Thanks,
Sander

Hi Sander,

thanks for letting us know.

–Fons