Subj : speed-up critical regions To : comp.programming.threads From : amorox Date : Tue Jun 14 2005 05:13 pm Hi everybody, I'm trying to optimize the time needed to enter in a critical region when it is consecutively executed in the same thread. My idea was to use the RECURSIVE mutexes since the cost of a 'lock' on an owned mutex is much less than on a non-owned mutex. So, I tried something like this: function init() { create RECURSIVE mutex; lock(mutex); } function critical_region() { if (trylock(mutex)) { // costs nothing if the mutex is owned by the current thread unlock(mutex); // problem - I'm not the owner of the mutex lock(mutex); lock(mutex); } work(); unlock(mutex); } function destroy() { unlock(mutex); destroy mutex; } As you can see the problem is in the 'unlock' operation I have to do without being the mutex owner. Is there any portable code for this? Thankfully, Ovidiu .