Re: Is there a primitive to atomically release a spinlock and goto sleep?

From: Andy Lutomirski
Date: Wed Sep 01 2010 - 22:16:51 EST


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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/