PDA

View Full Version : Problems with Qsemaphore and QThread



perseo
23rd August 2008, 02:12
Hello,
i have the next problem:

- I use two threads, because i would like to display two videos.
- I would like to synchronize these two videos with one semaphore.
- In the code of the threads i have one connect (connect the timer and the funcion xx to update the label) to display the frame and one timer to update with this refresh.
- In the function xx i have one sem.acquire() to block this frame until the other is available, and in the other function another sem.acquire if the other comes first. And one sem.release() in these functions to release the semaphore.

My problem is that my application is freeze, and when the semaphore is blocked, then it doesn't receive the sem.release. I don't know what's happened...

Thanks!

perseo
23rd August 2008, 14:09
I answer me now with another question.

I read that "if you create a QTimer object in a thread but never call exec(), the QTimer will never emit its timeout() signal".

Then in run() i introduce exec() and my appplication doens't freeze, but the timeout never emits signal....

I have to introduce more things?

jacek
27th August 2008, 02:21
Do you really need two threads? Can't you read those frames one after another in one thread? Because if you use semaphores to block threads, you also block the timers that live in those threads.

When it comes to the timer: if you create the timer inside run() and make a connection between the timer object and the thread object, make sure you force the connection type to Qt::DirectConnection. If you use the same timer for both threads and the timer lives in the GUI thread, the connection type should be Qt::QueuedConnection.