Linux waiting queue Article 3

Source: Internet
Author: User

1. Why do I need to use the waiting queue? Waiting queue is a necessity for the drive of blocking character devices. Blocking indicates that a device is readable or writable. However, at some point, the device has nothing to read from you, but your application (process) operations need to read data from the device, there is no way, either an error occurs, or the block is there waiting to read the data. Once the device has something to read to you, the process can continue the read operation.

2. Define and initialize the waiting queue.

(1) Define "waiting queue Header"
Wait_queue_head_t my_queue;
(2) initialize the "waiting queue Header"
Init_waitqueue_head (& my_queue );
Define and initialize shortcuts:
Declare_wait_queue_head (my_queue );

3. Where can I use the waiting queue? In your operation function. For example, read or write operations.

Wait_event (queue, condition );
Wait_event_interruptible (queue, condition );
Wait_event_timeout (queue, condition, timeout );
Wait_event_interruptible_timeout (queue, condition, timeout );
Wait for the first parameter queue to be awakened as the waiting queue header, and the second parameter condition must be met; otherwise, it will be blocked. The difference between wait_event () and wait_event_interruptible () is that the latter can be interrupted by signals, but the former cannot. The macro after timeout indicates the timeout time of the blocking wait. In jiffy, when the timeout of the third parameter arrives, no matter whether the condition is satisfied or not, it is returned.

4. Where to wake up and how to wake up? The wake-up method corresponds to the waiting event.

Void wake_up (wait_queue_head_t * Queue );
Void wake_up_interruptible (wait_queue_head_t * Queue );
The above operation will wake up all processes corresponding to the waiting queue with the queue as the waiting queue header.
Wake_up () <---> wait_event ()
Wait_event_timeout ()
Wake_up_interruptible () <---> wait_event_interruptible ()
Wait_event_interruptible_timeout ()

Wake_up () can wake up processes in task_interruptible and task_uninterruptible.
Wake_up_interruptble () can only wake up processes in task_interruptible.

The wake-up operation is generally executed in the interrupt program. Remember that condition must be assigned true to truly wake up !!

 

Source: http://markter.blog.163.com/blog/static/173553995201182875330918/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.