This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Why to signal condvar with mutex held?
- From: Sergei Organov <osv at topconrd dot ru>
- To: Nick Garnett <nickg at ecoscentric dot com>
- Cc: ecos-discuss at sources dot redhat dot com
- Date: 24 Nov 2004 17:54:04 +0300
- Subject: Re: [ECOS] Why to signal condvar with mutex held?
- References: <87llcro1eq.fsf@osv.topcon.com> <m3r7mjgvqi.fsf@xl5.calivar.com>
Nick Garnett <nickg@ecoscentric.com> writes:
> Sergei Organov <osv@topconrd.ru> writes:
[...]
> > 3. If both of the above are true, isn't it better to signal/broadcast
> > with mutex unlocked?
>
> Condition variables are seldom used on their own. There is usually
> some other data that encodes the condition being waited for. This data
> needs to be protected with a mutex.
Yes, sure, the data should be accessed only while mutex is locked, but
the question is isn't it better to unlock the mutex *before*
signalling/broadcasting condvar, as opposed to doing it *after*
signalling/broadcasting?
>
> eCos does allow a condition variable to be signalled without taking
> the mutex, but this has somewhat limited use. It is mainly used in
> device driver DSR routines to wake a waiting thread up. There the role
> of the mutex is played by taking the scheduler lock, or disabling
> interrupts.
I didn't mean the case when mutex is not used at all, -- I've meant to
ask only about what should be better to do first, mutex unlock or
condvar signal.
--
Sergei.
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss