Wait Queue Example

Table of Contents

1 Wait queue introduction

Wait queues are used to wait for particular conditions to be true, and to sense data and resource availability. Every process want to sleep is queued in the task_list in wait queue and put into sleep state until a condition becomes true.

2 Wait queue API

The functions related to wait queue are defined in <linux/wait.h>, all these functions are as following:

  • Static declaration:
    DECLATION_WAIT_QUEUE_HEAD(name)
  • Dynamic declaration:
    wait_queue_head_t my_wait_queue;
    init_waitqueue_head(&my_wait_queue);
  • Blocking:
    int wait_event_interruptible(wait_queue_head_t q, CONDITION);
  • Unblocking:
    void wake_up_interruptible(wait_queue_head_t *q);

3 Example Code

Author: Yanqing.Li

Created: 2019-04-20 六 16:29

Validate