1

在跟踪等待系统调用的路径时,注意到在调用 do_wait_thread 之前我们获取了 tasklist_lock。我试图了解 tasklist_lock 的重要性以及它适合使用的地方。

716        read_lock(&tasklist_lock);
1717        tsk = current;
1718        do {
1719                retval = do_wait_thread(wo, tsk);
1720                if (retval)
1721                        goto end;
1722
1723                retval = ptrace_do_wait(wo, tsk);
1724                if (retval)
1725                        goto end;
1726
1727                if (wo->wo_flags & __WNOTHREAD)
1728                        break;
1729        } while_each_thread(current, tsk);
1730        read_unlock(&tasklist_lock);

我看了一下tasklist_lock的声明,如下。

/*
 251 * This serializes "schedule()" and also protects
 252 * the run-queue from deletions/modifications (but
 253 * _adding_ to the beginning of the run-queue has
 254 * a separate lock).
 255 */
 256 extern rwlock_t tasklist_lock;
 257 extern spinlock_t mmlist_lock;

我无法理解我们应该在哪里使用它。你能告诉我这件事吗?感谢你的帮助。

4

1 回答 1

2

循环遍历当前任务的每个线程。持有任务列表锁可确保循环运行时这些线程都不会消失。

于 2012-04-05T02:32:59.827 回答