Linux内核默认工作者线程的处理

来源:互联网 发布:企业一套表软件 编辑:程序博客网 时间:2024/05/29 16:21

摘至:http://www.makelinux.net/books/lkd2/ch07lev1sec4

Let's look at the heart of worker_thread(), simplified:

for (;;) {        set_task_state(current, TASK_INTERRUPTIBLE);        add_wait_queue(&cwq->more_work, &wait);        if (list_empty(&cwq->worklist))                schedule();        else                set_task_state(current, TASK_RUNNING);        remove_wait_queue(&cwq->more_work, &wait);        if (!list_empty(&cwq->worklist))                run_workqueue(cwq);}

This function performs the following functions, in an infinite loop:

  1. The thread marks itself sleeping (the task's state is set to TASK_INTERRUPTIBLE) and adds itself to a wait queue.

  2. If the linked list of work is empty, the thread calls schedule() and goes to sleep.

  3. If the list is not empty, the thread does not go to sleep. Instead, it marks itselfTASK_RUNNING and removes itself from the wait queue.

  4. If the list is nonempty, the thread calls run_workqueue() to perform the deferred work.

0 0
原创粉丝点击