Kernel waiting queue mechanism

Source: Internet
Author: User
Kernel waiting queue mechanism Introduction-general Linux technology-Linux programming and kernel information. The following is a detailed description. I believe that many write programs have written socket programs. When we open a socket, we will continue to read the socket. If there is no data available for reading at this time, the read will block it. (This is because O_NONBLOCK is not added.) It will not be passed back until the data is readable. In Linux kernel, there is a data structure that can help us achieve this function. This data structure is the wait queue to be introduced here. In kernel, wait_queue is widely used. wait_queue is used for implement in device driver semaphore and other aspects. Therefore, it is a basic data structure in the kernel.
  
Next, I will introduce you to wait_queue usage and use an example to illustrate how to use wait_queue. Finally, I will take you to trace the original program code of wait_queue and see how wait_queue is implemented.
  
I would like to mention the difference between Linux user space and kernel space. We know that Linux is a multi-tasking environment, and many people can execute many programs. This is from the user's point of view. From the perspective of kernel, there is no so-called multi-tasking. In kernel, only single-thread is supported. That is to say, if your kernel code is being executed, only that part of the system is being executed. No other part of the kernel code is also running. Of course, this refers to single processor. If it is SMP, I don't know. I think many people have written programs in Windows 3.1 and write programs in that environment. Every program must properly give the CPU to other programs. If a program contains
  
CODE: while (1 );

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.