In-class notes for 10/07/2019
CS 273 (OS), Fall 2019
Shell assignment due tonight. Questions?
Help session for virtual machines lab?
Does your laptop have enough disk space (~20-25GB)? 64-bit processor? No laptop? -- if these are issues for you, see RAB
HW8, due Wednesday
Scheduling - discussed today
File I/O in C language
FILE
operations, in preparation for next project (along with threads and sockets)Code example:
FILE.c
Scheduling
Recall process states:
In process management within an OS, scheduling means choosing the next running process among all the runnable processes
Exercise per table: come up with three or more factors or goals a scheduler might consider, then report out. Some examples:
- Fairness
- Response time
- Handle both I/O bound and compute bound processes
Some terms related to scheduling (see text for definitions)
Some algorithms for scheduling
IPC
Thread-safe data structure exercise with Message Passing
Synchronization server's code
int A[MAXARRAY]; REPEAT FOREVER: receive(&any, &msg) // receive msg from any proc; remember that proc if type(msg) == GET_ARRAY retmsg = make_msg(GET_RESPONSE, A[index(msg)]) send(any, retmsg) else if type(msg) == SET_ARRAY A[index(msg)] = val(msg) retmsg = make_msg(OK_MSG) send(any, retmsg) else retmsg = make_msg(INVALID_TYPE_MSG, type(msg)) send(any, retmsg)
Client processes' library functions
function get_array(i) msg = make_msg(GET_ARRAY, i) send(sync, msg) receive(sync, &retmsg) return val(retmsg) function set_array(i, val) msg = make_msg(SET_ARRAY, i, val) send(sync, msg) receive(sync, &retmsg)
Producer-consumer problem - a richer problem than the simple thread-safe data structure problem
Needs thread-safety for its buffer data structure (array of items)
Block if necessary for mutual exclusion, as before
But also requires that:
a producer blocks if necessary until a slot becomes available when the buffer is full; and
a consumer blocks if necessary until an item becomes available, when the buffer is empty.
These multiple needs for blocking must be handled with correct IPC.
Solutions to producer-consumer problem using semaphores, monitors, message passing
< >