All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@mit.edu>
To: David Nicol <davidnicol@gmail.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Is there a primitive to atomically release a spinlock and go to sleep?
Date: Wed, 01 Sep 2010 22:16:13 -0400	[thread overview]
Message-ID: <4C7F08ED.9010901@mit.edu> (raw)
In-Reply-To: <AANLkTimZnUEM6FFbgw==K3w6hURAgsAO8uRh5W1v6f_j@mail.gmail.com>

David Nicol wrote:
> I'm trying to do something involving multiple kthreads in an ioctl
> handler, and I want to avoid the
> race condition between the third and fourth steps of
> 
>     acquire mutex
>     add &self to a list of threads which will get awakened by
> something else that is also aware of this list
>     release mutex
>     go to sleep
> 
> Is there a standard atomic go-to-sleep function that takes as a
> parameter a pointer to  spinlock to release after its state is set to
> TASK_INTERRUPTIBLE?

That wouldn't be enough -- the other thread could try to wake you up before you're even in the list of threads.

Look at wait_event_*() or read this:

http://book.chinaunix.net/special/ebook/PrenticeHall/PrenticeHallPTRTheLinuxKernelPrimer/0131181637/ch03lev1sec7.html

--Andy

      reply	other threads:[~2010-09-02  2:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-02  1:04 Is there a primitive to atomically release a spinlock and go to sleep? David Nicol
2010-09-02  2:16 ` Andy Lutomirski [this message]

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=4C7F08ED.9010901@mit.edu \
    --to=luto@mit.edu \
    --cc=davidnicol@gmail.com \
    --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 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.