apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Victor J. Orlikowski" <v.j.orlikow...@gte.net>
Subject Re: Conditionals...
Date Tue, 31 Jul 2001 20:24:18 GMT
 > I've been looking into this over the last few days and although I'm
 > totally in favor of adding condition variables to APR, I'm not yet
 > convinced that we can properly implement them on non-POSIX platforms
 > without some level of kernel support. There is one specific place where
 > I'm seeing a problem:
 > 
 > - cond_wait() takes a locked mutex that is associated with the cond.
 > - it will unlock that mutex and go to sleep
 > - when it awakens it must immediately reacquire that mutex (awaken() and
 >   acquire() must be a single atomic operation)
 > - finally, cond_wait() returns.
 > 
 > Does anyone know of a way around this without some sort of kernel support
 > to make those two operations atomic? This seems like a serious potential
 > for race/deadlocks.

*Sigh.*

As I told David (off-list),
If you have mutexes or semaphores, you can implement condition
variables.
Period.

Hint: Use another mutex, right after you go to sleep.

i.e.

release(mutex1);
sleep();
acquire(mutex2);
acquire(mutex1);
release(mutex2);

Victor
-- 
Victor J. Orlikowski   | The Wall is Down, But the Threat Remains!
==================================================================
v.j.orlikowski@gte.net | orlikowski@apache.org | vjo@us.ibm.com

Mime
View raw message