Thread synchronization

I have an application (a video player), that uses three threads to play videos (one thread handles decoding, another video display, and another audio). These threads have a thread barrier to wait until all 3 threads finish. This works fine. Now, my video player supports playing back two movies at the same time (to have one as a background and one as a foreground). Currently this is done with the same code for both. My problem is that there's no sync between the two movies and I am puzzled on how to achieve synchronism. I am unsure whether a thread barrier can be waited twice by two threads or whether I should have a single barrier that waits on the 6 threads ( 2 decode, 2 video, 2 audio ). If someone has any insight, it would be appreciated.

Le 06/12/13 00:02, Gonzalo Garramuno a écrit :
I have an application (a video player), that uses three threads to play videos (one thread handles decoding, another video display, and another audio). These threads have a thread barrier to wait until all 3 threads finish. This works fine. Now, my video player supports playing back two movies at the same time (to have one as a background and one as a foreground). Currently this is done with the same code for both. My problem is that there's no sync between the two movies and I am puzzled on how to achieve synchronism. I am unsure whether a thread barrier can be waited twice by two threads or whether I should have a single barrier that waits on the 6 threads ( 2 decode, 2 video, 2 audio ). If someone has any insight, it would be appreciated.
Hi, Maybe you should group the 3 thread and a barrier as a single data structure that you instantiate twice. Best, Vicente

Hi, Maybe you should group the 3 thread and a barrier as a single data structure that you instantiate twice.
Best, Vicente Maybe I wasn't clear. I am doing just that right now. The problem is
On 06/12/13 18:23, Vicente J. Botet Escriba wrote: that the two barriers need to be in sync, so the foreground video and background video end together. I don't know whether I can have the foreground decode thread wait on the background barrier while the background barrier also waits in its own decode thread. Or whether I should go with a single barrier for both the background and the foreground.

Le 07/12/13 01:14, Gonzalo Garramuno a écrit :
Hi, Maybe you should group the 3 thread and a barrier as a single data structure that you instantiate twice.
Best, Vicente Maybe I wasn't clear. I am doing just that right now. The problem is
On 06/12/13 18:23, Vicente J. Botet Escriba wrote: that the two barriers need to be in sync, so the foreground video and background video end together. I don't know whether I can have the foreground decode thread wait on the background barrier while the background barrier also waits in its own decode thread. Or whether I should go with a single barrier for both the background and the foreground. I can not help you to define the problem you need to solve ;-) If you clarify the synchronization points between the 6 threads tis would surely help. Take in account that we are not aware of your problem domain
Maybe you just need to have 3 barriers, one for each group of the 3 threads and an additional one to synchronize the end of the 6 threads. HTH, Vicente
participants (2)
-
Gonzalo Garramuno
-
Vicente J. Botet Escriba