Synchronizing tsleep() and wakeup()
Synchronizing tsleep() and wakeup()
- Subject: Synchronizing tsleep() and wakeup()
- From: Eric Long <email@hidden>
- Date: Mon, 02 Aug 2004 10:54:01 -0700
Hi,
I've been trying to use tsleep() and wakeup() in a kernel extension, but it
isn't obvious to me how to enforce synchronization of these calls. (Likely,
this isn't the right mechanism for what I want. But, since I'm not sure
what I need to use, I'm bringing it up here.)
My goal is to put a thread Y to sleep until a condition is met or a time out
occurs. Thread Z is manipulating the condition, then calling wakeup on
Thread Y when it changes. But if thread Z's timing is just right (or should
I say wrong) thread Y may call tsleep after thread Z has decided whether or
not to wake it up.
Searching for a condition lock, I came to this page:
<
http://developer.apple.com/documentation/Darwin/Conceptual/KernelProgrammin
g/synchronization/chapter_15_section_3.html#//apple_ref/doc/uid/TP30000905-C
H218-TPXREF109>
Which says:
>
The BSD portion of Mac OS X provides tsleep, wakeup, and wakeup_one, which are
>
equivalent to condition variables with the addition of an optional time-out.
>
Since they are more commonly used for waiting a predetermined period of time,
>
these calls are discussed in more detail in the section 3Using tsleep2 as part
>
of the 3Miscellaneous Kernel Services2 chapter.
In my case, I'm not waiting for a predetermined amount of time. In fact, I
may not need to wait at all, if the other thread has changed the value, and
ultimately I only want to sleep until the value has changed or we time-out
and give up waiting for the change.
What's the best way to do this in the kernel?
Thanks,
Eric
_______________________________________________
darwin-kernel mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/darwin-kernel
Do not post admin requests to the list. They will be ignored.