mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: Larry Finger <Larry.Finger@lwfinger.net>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: Question regarding mutex locking
Date: Wed, 28 Nov 2007 16:22:57 +0100	[thread overview]
Message-ID: <jemysy2y3y.fsf@sykes.suse.de> (raw)
In-Reply-To: <474CF06C.8020208@lwfinger.net> (Larry Finger's message of "Tue\, 27 Nov 2007 22\:37\:00 -0600")

Larry Finger <Larry.Finger@lwfinger.net> writes:

> If a particular routine needs to lock a mutex, but it may be entered with that mutex already locked,
> would the following code be SMP safe?
>
> hold_lock = mutex_trylock()
>
> ...
>
> if (hold_lock)
> 	mutex_unlock()

When two CPUs may enter the critical region at the same time, what is
the point of the mutex?  Also, the first CPU may unlock the mutex while
the second one is still inside the critical region.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

  parent reply	other threads:[~2007-11-28 15:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-28  4:37 Larry Finger
2007-11-28  8:10 ` Matthias Kaehlcke
2007-11-28 14:46   ` Larry Finger
2007-11-28 15:00     ` Matthias Kaehlcke
2007-11-28 15:22 ` Andreas Schwab [this message]
2007-11-28 15:41   ` Larry Finger
2007-11-28 22:45     ` Jarek Poplawski
2007-11-28 22:56       ` Jarek Poplawski
2007-11-28 23:07         ` Jarek Poplawski
2007-11-28 23:33       ` Stephen Hemminger
2007-11-29  6:40         ` Jarek Poplawski
2007-11-30  1:13 ` Bryan O'Sullivan
     [not found] <fa.C9TdvYAhY8SablNc39IpD8WDnNM@ifi.uio.no>
2007-11-28  4:53 ` Robert Hancock
2007-11-28  5:19   ` Larry Finger
2007-11-29  2:34     ` David Schwartz
2007-11-29  7:56       ` Jarek Poplawski

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=jemysy2y3y.fsf@sykes.suse.de \
    --to=schwab@suse.de \
    --cc=Larry.Finger@lwfinger.net \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome