Work queue and wait queue are silly to know!

Source: Internet
Author: User
The work queue and the wait queue are silly to be clearly divided.     Work queue is a bottom half, the second half of the interrupt processing, emphasizing the dynamic concept that work is the focus, and the queue is followed. Wait queue is a "task queue" that can put some processes above sleep waiting for an event, emphasis on static more, focus on the queue, that is, it is a queue, this queue how to schedule, when scheduling is not important. One, waiting queueWaiting queues have many uses in the kernel, especially for interrupt handling, process synchronization, and timing. We are only saying here that processes often have to wait for certain events to occur. For example, wait for a disk operation to terminate, wait for the system resource to be freed, or wait for a fixed interval.
The waiting queue implements the conditional wait on the event, expecting the process of waiting for a particular event to put itself in the right waiting queue and relinquish control. So. The wait queue represents a set of sleeping processes that are awakened by the kernel when a condition is true.
The wait queue is implemented by a circular chain, and its elements include pointers to the process descriptor. Each wait queue has a waiting queue header, and the wait queue header is a data structure of type wait_queue_head_t.
The wait queue header is defined as follows:
struct __wait_queue_head { 
	wq_lock_t lock; 
	struct List_head task_list;	   Pointer to process descriptor 
}; 
typedef struct __WAIT_QUEUE_HEAD   wait_queue_head_t;  
Each element of the waiting queue list represents a sleep process that waits for an event to occur, and its descriptor address is stored in the task field. However, it is sometimes inconvenient to wake up all the processes in the waiting queue. For example, if two or more processes are waiting for a mutually exclusive access to a resource to be freed, only one of the waiting queues will be meaningful.     This process occupies resources, while other processes continue to sleep. You can define a new wait queue with the Declare_wait_queue_head (name) macro that statically declares and initializes a wait queue header variable with the alias name. The Init_waitqueue_head () function initializes the dynamically allocated wait queue head variable. Wait queues can be created statically by Declare_waitqueue (), or they can be created dynamically with Init_waitqueue_head (). The process puts itself into the waiting queue and is set to an executable state.
Second, Work queueWork queue, Workqueue, which allows kernel code to request a function to be called at some time in the future.     A method for handling callback methods that are not very urgent events. The role of the Task Force column is to postpone the work to a kernel thread, and more directly, if you write a function and you don't want to execute it right now, you want to do it at some point in the future.
You should also use the Task Force column if you need to perform the second half of your work with a scheduler entity. It is the only mechanism that can be implemented in the lower half of the interrupt context, and only it can sleep. This means that when you need to get a lot of memory, when you need to get semaphores, it is useful when you need to perform blocking I/O operations.

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.