In-class notes for 09/18/2020
CS 273 (OS), Fall 2020
Shell project - Due on Monday "midnight"
HW5, due Wednesday (available tomorrow)
More IPC; programing with pthreads
Thread-safe data structure (a single integer) - the implementation prevents race conditions for that data structure's shared memory locations
Exam date - will send poll
Lab: setting up a virtual machine
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
< >