1,277
edits
Changes
→KThread.join(): formatting
=={{c|KThread.join()}}==
===Implementation===
{{c|KThread}} has a new state variable {{c|joinedOnMe}}, a {{c|ThreadQueue}}.
===Testing===
* ThreadA {{c|threadA}} prints out a few statements, calls ThreadB{{c|threadB.join()}}, then prints out a few more statements. ThreadB {{c|threadB}} also prints out a series of statements. We want to then verify that ThreadB {{c|threadB}} executes contiguously to completion before ThreadA {{c|threadA}} resumes its execution, as evidenced by the sequence of printed statements. * Have a thread attempt to {{c|join ()}} to itself, and call {{c|join() on the same (but different) thread multiple times, and also attempt to call {{c|join ()}} on a finished thread(all separately). These should all return immediately because as this is the join condition was not satisfiedexpected behavior.* Have Test a chain of threads. Thread C will attempt to join Thread B. Thread B will attempt to join Thread A. Thread A forks last. Verify that A executes before B, and B executes before C.
===Pseudocode===
{{c|<pre>join() {
Disable interrupts;
If (CurrentThread == self or isJoined) or (status is Finished) {
}
Re-enable interrupts;
}</pre>}} {{c|<pre>finish(){
// Interrupts have been disabled.
...(existing code)...
Ready the thread in on the joinedOnMe queue;
Sleep (existing);
}</pre>}}
==Condition.java==