[ECOS] Condvars usage for DSR/thread synchronization.

Sergei Organov osv@javad.ru
Thu Jan 30 10:28:00 GMT 2003


Maybe I'm missing something obvious, but I didn't find any discussion of this
issue in the eCos documentation, so I'm asking here. How exactly a condvar is
supposed to be used when signalling of the condvar is to be invoked from a
DSR?

According to the eCos documentation, a thread should execute the following
code to wait on a conditional variable:

  cyg_mutex_lock( &mutex );
  ...
  while( condition_not_true )
    cyg_cond_wait( &cond );
  ...
  cyg_mutex_unlock( &mutex );

In the case when 'cond' is to be signalled from a DSR (that is indeed
explicitly allowed by the eCos documentation), 'mutex' seems to be of no use
as operations on mutexes are not allowed from DSRs. Another mechanism should
be used to protect 'condition' from simultaneous access by the thread and the
DSR. Apparently 'cyg_scheduler_[un]lock()' is an appropriate tool for that.
The thread should then execute the following code(?):

  cyg_scheduler_lock();
  cyg_mutex_lock( &mutex );
  ...
  while( condition_not_true )
    cyg_cond_wait( &cond );
  ...
  cyg_mutex_unlock( &mutex );
  cyg_scheduler_unlock();

The resulting code looks rather strange as 'cyg_mutex_[un]lock()' calls seem
to be redundant. On the other hand, we apparently can't remove them as
'cyg_cond_wait()' requires the mutex to be locked, I believe.

Is condvar really supposed to be used this way?

Thanks in advance.

Sergei.


-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss



More information about the Ecos-discuss mailing list