SD os

concurrency

problem: how to handle concurrency problem using yield? And the problems encountered.(from lecture 5)

yield(): suspends the running thread, chooses a new thread to run, and resumes the new thread

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
yield(): 
acquire(t_lock)
// Suspend the running thread
id = cpus[CPU].thread
threads[id].state = RUNNABLE
threads[id].sp = SP
threads[id].ptr = PTR
// Choose a new thread to run
do:
id = (id + 1) mod N
while threads[id].state != RUNNABLE
// Resume the new thread
SP = threads[id].sp
PTR = threads[id].ptr
threads[id].state = RUNNING
cpus[CPU].thread = id

release(t_lock)

virtual machines

Scenario: running multiple Ones on a single physical machine.

problem: how to safely share physical hardware?