Previous | Next --- Slide 10 of 83
Back to Lecture Thumbnails
qwerty

Here, thread 1 spawns a second thread. Threads 1 and 2 execute in the same address space, so if thread 1 writes something in this address space, later thread 2 can read it and retrieve what the first thread wrote. In this code, thread 2 will not do anything until it observes the effect of the write by thread 1. Then it executes the rest of the code which will result in the number 1 being printed.

qwerty

In summary, communication between threads happens by reading and writing shared variables.

Please log in to leave a comment.