Skip to contentSkip to conversation

mutex locking

Xenomai-help Tobias Bär 1 participant 1 message Jun 21, 2006

lore
Share & tools
lore
#0 lore raw
Quoted 10 lines

Try this, it's safe from such races:

/* returns -EWOULDBLOCK if the mutex is locked */
if (rt_mutex_lock(&write_mutex,TM_NONBLOCK) == 0)

{
      // do sth.

      rt_mutex_unlock(&mutex);
}

Thank's for the quick reply! But another question: How could it be that a mutex is locked twice?

if(rt_mutex_lock(&write_mutex,TM_NONBLOCK) == 0)

  {
    if(rt_mutex_lock(&write_mutex,TM_NONBLOCK) == 0)
      printf("Mutex is locked twice!\n");
   rt_mutex_unlock(&mutex);
  }

Is it locked by the ID of the thread?

Tobias