All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [Xenomai-help] mutex locking
@ 2006-06-21  9:58 Tobias Bär
  0 siblings, 0 replies; 5+ messages in thread
From: Tobias Bär @ 2006-06-21  9:58 UTC (permalink / raw)
  To: xenomai


> 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




^ permalink raw reply	[flat|nested] 5+ messages in thread
[parent not found: <216532953@domain.hid>]
* [Xenomai-help] mutex locking
@ 2006-06-21  9:37 Tobias Bär
  2006-06-21  9:46 ` Jan Kiszka
  2006-06-21  9:58 ` Philippe Gerum
  0 siblings, 2 replies; 5+ messages in thread
From: Tobias Bär @ 2006-06-21  9:37 UTC (permalink / raw)
  To: xenomai

Hi all,

my question is about the right way to lock and inquire a mutex. At time, my code looks like this:


rt_mutex_inquire(&mutex,TM_NONBLOCK);

if(info.lockcnt == 0) 
{
      rt_mutex_lock(&write_mutex,TM_NONBLOCK);

      // do sth.

      rt_mutex_unlock(&mutex);
}


What happens if anyone locks the mutex between my "rt_mutex_inquire(...)" and my "if(info.lockcnt == 0)" ?

Is this the standard way to lock and inquire a mutex?

Thanks,
  Tobias


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-06-21 10:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-21  9:58 [Xenomai-help] mutex locking Tobias Bär
     [not found] <216532953@domain.hid>
2006-06-21 10:32 ` Jan Kiszka
  -- strict thread matches above, loose matches on Subject: below --
2006-06-21  9:37 Tobias Bär
2006-06-21  9:46 ` Jan Kiszka
2006-06-21  9:58 ` Philippe Gerum

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.