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