In-class notes for 09/16/2020
CS 273 (OS), Fall 2020
Today - IPC before proceeding to in-person Virtual Box lab (Friday)
Will send google doc (via Piazza) to determine who else be in-person, who remote
Seek to include everyone with prerequisites only background (who wants to come)
Safety for in-person help: TA(s) and I will have face shield + mask, with time limits for close proximity
Look on Piazza for prep steps to carry out before Friday class (e.g., software download)
IPC
Example problem: thread-safe array
A shared data structure - any thread should have access to read or write elements of that array.
Risk of race condition for each element.
Basic operations needed:
set_array(array, index, value)
- compare to assignmentarray[index] = value
get_array(array, index)
- compare to value ofarray[index]
Exercise: Assuming an implementation of semaphores in your OS, give a pseudocode implementation of:
set_array()
get_array()
Note: Be sure to specify the initial value of any semaphore you use.
If time: check that your solution satisfies the four goals for correct IPC.
Semaphores
Review:
Data structures - each semaphore has a non-negative integer variable and a queue of blocked processes
Primitive operations are
down(sem)
andup(sem)
, implemented in OS as system callsExample: re-implementing
phtreads.c
to use semaphores instead of pthread locks.
Monitors
Summary of features:
A monitor is a programming-language entity, similar to an object
Mutual exclusion is guaranteed for a monitor's "methods" - no two threads can execute methods for the same monitor at the same time
Special data structures called condition variables, which are queues of blocked processes
Primitive operations
wait(condvar)
andsignal(condvar)
We will assume that both of these calls relinquish mutual exclusion
but caller ofwait()
gets mutual exclusion back when it becomes unblocked (i.e., by another process callingnotify()
Exercise: Assuming monitors in your programming language, give a pseudocode implementation of:
set_array()
get_array()
If time: check that your solution satisfies the four goals for correct IPC.
Message Passing
Summary of features:
Message passing involves transmitting data between processes/threads that could be on other (networked) computers
Data structures are messages (data to be transmitted) and a queue of pending messages for each destination (process/thread that can receive a message).
Primitive operations
send(dest, msg)
andreceive(src, &msg)
, for transmitting a messagemsg
from a source processsrc
to a destination processdest
.We will assume that
send()
is non-blocking andreceive()
is blocking (calling process blocks if there is no message to receive).
Unlike semaphores and monitors, note that message passing does not require that all processes run on the same computer.
Exercise: Assuming message passing between processes/threads, give a pseudocode implementation of:
set_array()
get_array()
Hint: Use a separate process/thread for managing the shared data structure.
If time: check that your solution satisfies the four goals for correct IPC.
Implementations of producer-consumer problem
To study for quiz
Process diagrams, including redirection of output, pipelines, etc.
Process states -- be ready to discuss how OS services (e.g., I/O operations, scheduling, system calls such as
wait()
, interrupt handling) relate to the process-state diagramAlgorithms and data structures for processes:
Process table -- Array of process table entries; each PTE contains information relevant to a particular process. Have a general familiarity with type of information (see examples).
Interrupt vector
Algorithm for handling interrupts -- study these steps, and ask any questions on Piazza or on questions of the day for next class meeting.
Programming with system calls: be prepared to write segments of C code that may use any of the following system calls: fork(), execve(), wait()
References:
~rab/os/forkeg.c
, and steps 2-4 of Strategy for developing a shellArguments - see man pages for system calls fork, execve, wait
< >