[Zion] Update FIXME in threading.

This commit is contained in:
Drew Galbraith 2023-11-02 22:36:48 -07:00
parent 78624d5291
commit 1643f7b4cc
1 changed files with 11 additions and 2 deletions

View File

@ -69,7 +69,7 @@ void Thread::Exit() {
#endif
state_ = FINISHED;
process_.CheckState();
while (!blocked_threads_.size() == 0) {
while (blocked_threads_.size() != 0) {
auto thread = blocked_threads_.PopFront();
thread->SetState(Thread::RUNNABLE);
gScheduler->Enqueue(thread);
@ -78,7 +78,16 @@ void Thread::Exit() {
}
void Thread::Wait() {
// FIXME: We need synchronization code here.
// TODO: We need synchronization code here.
// Race condition is for A waiting on B.
// 1. A checks if B is finished.
// 2. Context Switch A -> B
// 3. B finishes.
// 4. Context Switch B -> A
// 5. A forever blocks on B.
if (state_ == Thread::FINISHED) {
return;
}
auto thread = gScheduler->CurrentThread();
thread->SetState(Thread::BLOCKED);
blocked_threads_.PushBack(thread);