Running a gui with a thread

Hi,

I’ve uploaded a short macro which creates a very simple gui. The gui has a little red box in a canvas. There are two buttons called ‘Run In Thread’ and ‘Run In Series’. Both of these buttons call the same function which moves the box along. However, one of the them is run in a thread and one is not. For the threaded case, you can click on and click off the button to make it start/stop. For the serial case you have to wait for it to finish (take 2 secs).

On my machine, the threaded version runs a lot lot slower than the serial version - even though the exact same function is called. I can’t figure out why this happens. Does anyone see the same behaviour - can you explain it?

The gui was partially built using the root gui builder - then I added my own stuff manually. There is a single class called myClass. I compile the macro using aclic and then just create a single instance.

I am using root 5.25/04 on os x 10.6.2 with gcc 4.2.1

thanks
Peter
myClass.C (4.45 KB)

Hi Peter,

The thread add a lock/unlock mechanism in the loop (e.g. for every canvas update). I think this explain the timing issue.
Note I didn’t try on Mac, there are probably some differences between platforms and between debug/optimized mode.

Cheers, Bertrand.

Hi Bertrand,

thanks for that - just playing around I put the update into a separate thread which runs concurrently. This seems to solve the performance problem. So I guess update must lock/unlock the calling thread rather than all threads (as TThread::Lock() would do)

thanks!
Peter