Re: waiting queue
Re: waiting queue
- Subject: Re: waiting queue
- From: Michael Smith <email@hidden>
- Date: Tue, 05 Dec 2006 11:11:53 -0800
devmaillists wrote:
Dear Michael,
thank you vey much.
It helped me much.
I have one question left where the documentation does not tell me the
whole story:
#define THREAD_UNINT 0 /* not interruptible
The sleep is guaranteed to return, and only when someone explicitly
wakes it up. It will return THREAD_AWAKENED.
#define THREAD_INTERRUPTIBLE 1 /* may not be restartable */
The sleep is guaranteed to return, but may do so for various reasons
(e.g. a signal has been sent to the thread). It will return
THREAD_AWAKENED if it was woken up explicitly, and THREAD_INTERRUPTED if
it was woken for some other reason. If it returns THREAD_RESTART (or
anything else) you should restart the sleep.
#define THREAD_ABORTSAFE 2 /* abortable safely */
The sleep is not guaranteed to return. This is a promise on your part
that the thread can be aborted (destroyed) while asleep without
affecting your code. Generally in the driver environment this is OK to
use while you hold no locks or resources (e.g. whilst waiting to get
into your driver), but otherwise you should avoid it. You are not
notified when the thread is aborted; it just never comes back.
As a general rule, if you believe that your hardware is reliable, use
THREAD_UNINT to be safe. Only use THREAD_INTERRUPTIBLE if your device
can block for an arbitrary amount of time (e.g. waiting for remote
hardware that may never respond); it is primarily useful when you may be
blocking a shell tool that wants to respond to control-C, or has some
timeout set up.
Note that if you are asleep waiting for hardware to do something, and
that hardware is configured for busmaster DMA, you should use
THREAD_UNINT unless you are *certain* that you can safely cancel the
DMA. You must never leave pending DMA active - even if you return an
I/O error, the memory that was passed to you as the destination for the
I/O may be re-used immediately for something else, or in some cases it
may even become invalid and cause a fatal machine check if your hardware
tries to access it.
- Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden