mutex locking
Quoted 10 lines
Try this, it's safe from such races:
/* returns
-EWOULDBLOCKif 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