[gst-devel] Multi-threaded queueing locking issues

zaheer at grid9.net zaheer at grid9.net
Tue Mar 20 22:46:51 CET 2001


On Tue, 20 Mar 2001, Brent Bradburn wrote:

> Brent Bradburn wrote:
> 
> > In other words, to avoid a deadlock, verify that you still WANT to wait AFTER you
> > acquire the lock.  Don't wait if you don't have anything to wait on (the logical
> > condition is already satisfied):
> >
> >               pthread_mutex_lock(&mut);
> >               while (x <= y) {
> >                       pthread_cond_wait(&cond, &mut);
> >               }
> >               /* operate on x and y */
> >               pthread_mutex_unlock(&mut);
> 
> Another approach (and the one I typically use) is POSIX semapores (sem_post(),
> sem_wait(), ...).  Posting a semaphore increases the count regardless of whether or
> not anyone is currently waiting on it.  This effect can be used to avoid race
> conditions without requiring additional application logic (e.g. mutexes).
> 
> 

Semaphores are a good idea, and would be more elegant.

Zaheer





More information about the gstreamer-devel mailing list