Synchronous vs Asynchronous Programming
Synchronous: Asynchronous:
Idea from Unit 2A
– We would like to do other things while waiting for an IO event
– To do so, we need independent streams of execution in a program:
– one requests data, then does something else instead of waiting – while another gets the data ready and stores it in memory
Virtual Process (Thread)
– a single stream of synchronous execution of a program – can be stopped and started
– co-exists with other threads sharing the same CPU
– each thread has its own stack
Idea behind threads:
____________
_________________
What do you expect the output of the program shown below? You can describe in words
What do you expect the output of the program shown below?
What do you expect the output of the program shown below?
Use this program for the following questions
Thread Implementation
Blocking:
– explanation:
– what happens to thread:
– what happens to the physical processor:
Data structures needed: Basic operation required:
1. What is the output for this program
2. Change the order of the calls to create_threads, what is the output
3. Remove the calls to join
4. Remove both calls to yield
5. Remove both calls to yield and join Done
6. Remove both calls to yield, and one of the joins. Is the result dependent on which join is removed?
7. Remove pong’s yield and ping’s join
8. Remove pong’s yield and pong’s join
9. Change the yield in ping to a block