- normal (blocking) behavour
-
read
: process blocks if no data is available and may return
less than requested
-
write
: process blocks if output buffer is full. write
returns once free space becomes available in output
buffer. Partial write possible.
- non-blocking behaviour
- open with
O_NONBLOCK
- both read and write return
-EAGAIN
- allows polling device
API: waitqueues
type:
wait_queue_head_t
linux/wait.h
Declaration:
/* compile time */
DECLARE_WAIT_QUEUE_HEAD(name);
/* run time */
wait_queue_head_t q;
init_waitqueue_head(&q);
Sleeping:
wait_event(queue, condition)
wait_event_interruptible(queue, condition)
wait_event_timeout(queue, condition, timeout)
wait_event_interruptible_timeout(queue, condition, timeout)
waking up sleeping processes:
void wake_up(wait_queue_head_t *queue);
void wake_up_interruptible(wait_queue_head_t *queue);
specialities:
- exclusive waits: wake only one process on queue (avoids
thundering herd).
wake_up
wakes up all non-exclusive waiters
and one exclusive waiter.
-
wake_up_nr, wake_up_interruptible_nr
: wake up to X exclusive
waiters
-
wake_up_interruptible_sync
: avoid (possible) immediate
rescheduling so that wake_up
will return.
deprecated:
void sleep_on(wait_queue_head_t *q);
void interruptible_sleep_on(wait_queue_head_t *q);