Idle-waiting Thread Joining

The initial version of EPOS-- you are currently working with implements thread joining with a simple trick:

1.
2.
3.
4.
5.
int Thread::join() {
    while(_state != FINISHING)
        yield();
    return *((int *)_stack);
}

That is, testing the state of the thread being waited for until it turns to FINISHING (line 2). To give other threads a chance to run, and thus terminate, the calling thread invokes yield after each test.

Line 4, which is not in the scope of this exercise, simply forwards the value left on the stack by the terminating thread to the waiting thread.

To do

You are requested to modify the implementation of Thread so that join() no longer wastes time sampling the waited thread status. It must be set to sleep until the waited-for thread terminates, and then waken up accordingly.