PDA

View Full Version : Thread Synchronization for specific thread



Timeshifter
25th March 2012, 20:25
Hi!
I am working on multithreaded project which is almost done, but now I want to use CUDA SDK which is dependent on thread it runs in.
So, basically what I want is to create object (let's call it CUDAObject) for all work with CUDA, which will "live" in its own thread and use this CUDAObject for execution of CUDA functions. I do not want to rewrite most of my project, so what I need is some mechanism of executing CUDA code in CUDAObject.
What I was about to do was to emit signals (from different objects in different threads) which are connected using queued connection to CUDA object and then somehow wait for the slot in CUDAObject to finish its execution.
Firstly I was about to do it using QMutexes, but they must be locked and unlocked in the same thread. Then I looked into QFuture, which sadly looks like it is dependent on QtConcurent, which runs in different thread. So, I would like to know, if there is a way to wait until the slot in the CUDAObject is finished. Can anyone help me?

wysota
25th March 2012, 21:24
Ok but what exactly do you want to protect using a mutex (or whatever else mechanism you would choose)?

Timeshifter
26th March 2012, 12:51
I want to wait until the computation in CUDAObject finishes.

wysota
26th March 2012, 13:16
In that case use a wait condition (QWaitCondition).