[ECOS] Nested calls to Mutexes

Andrew Lunn andrew.lunn@ascom.ch
Wed Mar 21 06:26:00 GMT 2001


> I disagree with this statement. It is a *common idiom* to have
> routines that needs to "lock" some access to start calling other
> routines that "locks" the mutex again.  

To me this is dangerous. Mutex's are used to protect state
information. I lock the mutex when im want to modify the state
information. The locked mutex indicates the state information may not
be consitent. 

Now you want the thread that locked the mutex to be able to call other
functions that also want to modify the state information. Those
functions have to be aware the state information could be
inconsitent. It cannot trust the information. Any changes it makes
could also make the other function which locked the mutex also go
wrong. 

You strongly tie the two functions together. Unless you know that this
is happening its very easy to make a mistake and create subtle bugs
which are hard to track down.

I say eCos is correct. It should throw an assertion when this
happens. I then know i have this sort of relationship going on and i
need to redesign my code,

If you do want the opertunity to shoot yourself in the foot, you could
modify your local copy of eCos. You have the source!

        Andrew



More information about the Ecos-discuss mailing list