All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: "Tobias Bär" <Tobias.Baer@domain.hid>
Cc: xenomai-help <xenomai@xenomai.org>
Subject: Re: [Xenomai-help] mutex locking
Date: Wed, 21 Jun 2006 12:32:52 +0200	[thread overview]
Message-ID: <44992054.70905@domain.hid> (raw)
In-Reply-To: <216532953@domain.hid>

[-- Attachment #1: Type: text/plain, Size: 1289 bytes --]

Tobias Bär wrote:
>> -----Ursprüngliche Nachricht-----
>> Von: Jan Kiszka <jan.kiszka@domain.hid>
>> Gesendet: 21.06.06 11:46:34
>> An: Tobias Bär <Tobias.Baer@domain.hid>
>> CC: xenomai@xenomai.org
>> Betreff: Re: [Xenomai-help] mutex locking
> 
>> 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?
> 

RTFM ;): "Xenomai mutexes are implicitely recursive [...]."

> 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?
> 

Yep, the owner is recorded, also to perform priority inheritance when
required. Recursive means that the current owner can acquire the mutex
multiple times (but (s)he also has to release it symmetrically then -
your example is lacking one unlock).

If you use the POSIX skin with its standard pthread_mutex'es, then you
can decide about the recursiveness explicitly.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

       reply	other threads:[~2006-06-21 10:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <216532953@domain.hid>
2006-06-21 10:32 ` Jan Kiszka [this message]
2006-06-21  9:58 [Xenomai-help] mutex locking Tobias Bär
  -- 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44992054.70905@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=Tobias.Baer@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.