This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Why to signal condvar with mutex held?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]