In-class notes for 10/02/2019
CS 273 (OS), Fall 2019
Quiz
Shell project - Due on Monday!
HW7, due Friday
More IPC; more pthreads
Thread-safe data structure (a single integer) - the implementation prevents race conditions for that data structure's shared memory locations
Next time - virtual machine lab
IPC
Exercise: build a thread-safe array with operations
set_array(array, index,
value)
and
get_array(array, index
)
Answer for first problem -- pseudocode for a solution for semaphores
semaphore s; init_sem(s, 1); def of set_array(A, i, val): down(s) A[i] = val up(s) def of get_array(A, i): return A[i]
Issues to consider
Locking entire array, yet modifying only one element.
Does this violate any IPC goals?
Would a semaphore per array element be better?Are semaphores needed to synchronize
get_array()
?
Does it depend on data type?
Two other IPC solutions we will consider besides semaphores: Monitors and Message Passing
< >