私はカーネル初心者です。ソースコードを読んでいるときに、この質問がありました。
の実装でwait_event()
は、カーネルは次のような処理を行います。
...
prepare_to_wait(); /* enqueue current thread to the wait queue */
...
schedule(); /* invoke deactivate_task() inside, which will dequeue current thread from the runqueue */
...
「wake_up()」の実装では、カーネルは次のことを行います。
...
try_to_wake_up(); /* invoke activate_task() inside, which will enqueue the target thread into the runqueue */
...
同時実行で、上記の関数が次の順序で呼び出されるとどうなるでしょうか。
...
prepare_to_wait(); /* thread A adds itself to the wait queue */
...
try_to_wake_up(); /* thread B wakes up A and enqueues it into the runqueue */
...
schedule(); /* thread A dequeues itself from the runqueue and yields the CPU */
...
スレッド A は、ランキューにも待機キューにもありません。スレッド A を失ったということですか?カーネルには、これを防ぐためのメカニズムが必要です。誰かが私がここで見逃したことを教えてもらえますか? ありがとう!