From: Jan Kiszka <jan.kiszka@domain.hid>
To: "Tobias Bär" <Tobias.Baer@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] mutex locking
Date: Wed, 21 Jun 2006 11:46:08 +0200 [thread overview]
Message-ID: <44991560.6030300@domain.hid> (raw)
In-Reply-To: <216509776@domain.hid>
[-- Attachment #1: Type: text/plain, Size: 730 bytes --]
Tobias Bär wrote:
> 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?
>
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);
}
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]
next prev parent reply other threads:[~2006-06-21 9:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-21 9:37 [Xenomai-help] mutex locking Tobias Bär
2006-06-21 9:46 ` Jan Kiszka [this message]
2006-06-21 9:58 ` Philippe Gerum
-- strict thread matches above, loose matches on Subject: below --
2006-06-21 9:58 Tobias Bär
[not found] <216532953@domain.hid>
2006-06-21 10:32 ` Jan Kiszka
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=44991560.6030300@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.