Valid contexts – Comtrol eCos User Manual

Page 69

Advertising
background image

Mutexes

When a thread has just locked a mutex associated with some data structure, it can assume that that data structure is
in a consistent state. Before unlocking the mutex again it must ensure that the data structure is again in a consistent
state. Recursive mutexes allow a thread to make arbitrary changes to a data structure, then in a recursive call lock
the mutex again while the data structure is still inconsistent. The net result is that code can no longer make any
assumptions about data structure consistency, which defeats the purpose of using mutexes.

Valid contexts

cyg_mutex_init

,

cyg_mutex_set_ceiling

and

cyg_mutex_set_protocol

are normally called during ini-

tialization but may also be called from thread context. The remaining functions should only be called from thread
context. Mutexes serve as a mutual exclusion mechanism between threads, and cannot be used to synchronize
between threads and the interrupt handling subsystem. If a critical region is shared between a thread and a DSR
then it must be protected using

cyg_scheduler_lock

and

cyg_scheduler_unlock

. If a critical region is shared

between a thread and an ISR, it must be protected by disabling or masking interrupts. Obviously these operations
must be used with care because they can affect dispatch and interrupt latencies.

69

Advertising