17.9.5. Wait queues
Wait queues are a way to make a thread sleep until an event happens on the queue:
insmod wait_queue.c
Dmesg output:
0 0 1 0 2 0 # Wait one second. 0 1 1 1 2 1 # Wait one second. 0 2 1 2 2 2 ...
Stop the count:
rmmod wait_queue
Source: kernel_modules/wait_queue.c
This example launches three threads:
-
one thread generates events every with
wake_up
-
the other two threads wait for that with
wait_event
, and print a dmesg when it happens.The
wait_event
macro works a bit like:while (!cond) sleep_until_event