Operating System Fundamentals 38 example, the first thread got to run but was not completed (it did not make it to the println()
function, then threadB ran and then threadA finished. Non-deterministic solutions are extremely dangerous in critical systems where peoples lives are at stake. Unfortunately we did not actually say what the desired output should actually look like. Let us suppose that we want the output to be in the order of Thread A followed by Thread B on the next line, and we want
to be guaranteed of this order, regardless of what else possibly happens. This suggests that we need some mechanism of making sure threadB waits for threadA to finish. As always, we would like to try to minimize the amount of CPU time actually used. This first thing
we will talk about is called synchronization.
Share with your friends: