Improve instructions, fix a function call that had been renamed in one place but not others

This commit is contained in:
Nathan Stocks
2021-11-12 11:32:27 -07:00
parent 7590bcc927
commit e1b22630a6

View File

@@ -55,24 +55,26 @@ fn main() {
// 4. Examine the flow of execution of "Thread A" and "Thread B" below. Do you see how their // 4. Examine the flow of execution of "Thread A" and "Thread B" below. Do you see how their
// output will mix with each other? // output will mix with each other?
// - Increase the value passed to the first `pause_ms()` call in "Thread A" so that both the // - Run this code. Notice the order of output from Thread A and Thread B.
// "Thread B" outputs occur before the "Thread A" outputs. // - Increase the value passed to the first `sleep_ms()` call in Thread A so that both the
// Thread B outputs occur *before* Thread A outputs anything.
// - Run the code again and make sure the output comes in a different order.
// Thread A // Thread A
let handle_a = thread::spawn(move || { let handle_a = thread::spawn(move || {
pause_ms(0); sleep_ms(0);
tx2.send("Thread A: 1").unwrap(); tx2.send("Thread A: 1").unwrap();
pause_ms(200); sleep_ms(200);
tx2.send("Thread A: 2").unwrap(); tx2.send("Thread A: 2").unwrap();
}); });
pause_ms(100); // Make sure Thread A has time to get going before we spawn Thread B sleep_ms(100); // Make sure Thread A has time to get going before we spawn Thread B
// Thread B // Thread B
let handle_b = thread::spawn(move || { let handle_b = thread::spawn(move || {
pause_ms(0); sleep_ms(0);
tx.send("Thread B: 1").unwrap(); tx.send("Thread B: 1").unwrap();
pause_ms(200); sleep_ms(200);
tx.send("Thread B: 2").unwrap(); tx.send("Thread B: 2").unwrap();
}); });