Due date: Monday, October 3rd
You must turn in your homework in written form by the beginning of class on the date it is due.
The questions are based on material presented in class and reading material from the text.
Give brief answers to the following questions:
Suppose your OS does not yet have semaphores but the computer
system does have the Test_and_Set()
function. Assuming
only a single semaphore is needed, implement the functions
wait(void)
and signal(void)
using the
Test_and_Set()
function as a user-level function. You
may use any shared boolean variables needed for your solution (i.e.
one or more "lock" variables). What are the potential drawbacks, if
any, of this semaphore implementation?
Following is an implementation of a producer-consumer mailbox that can contain one message at a time. In the below implementation, the consumer does not wait if the producer has not yet made a message. Using only semaphores, make the consumer print the message once if and only if there is a message in the mailbox created by the producer.
struct message mbox; /* shared */ producer() { struct message my_msg; while(1) { create_msg(&my_msg); /* create my message */ put_msg(mbox, my_msg); /* put my message in the mbox */ } } consumer() { struct message my_msg; while(1) { get_msg(&my_msg, mbox); /* get message from the mbox */ print_msg(my_msg); /* print my message */ } }
Consider an OS with the below process control block (PCB). Write another data structure that contains exactly enough information needed to support threads (a thread control block, or TCB). A thread should be able to access the containing process from the TCB.
struct PCB { int pid /* Process ID */ int state; /* ready, running or blocked */ int timeLeft; /* time left since last time slide */ struct SaveArea sa; /* hardware state to save */ struct InOut *pIO; /* pointer to IO descriptors */ struct Heap *pHeap; /* pointer to heap */ struct Stack *pStack; /* pointer to stack */ };
Briefly explain the difference between internal and external fragmentation. In particular, explain why paging has no external fragmentation. What kind of fragmentation do you have with variable sized partitions?
Consider a logical address space of 32 pages of 2048 bytes (words) each, mapped onto a physical memory of 64 frames.
Consider a paging system with the page table stored in memory.
Return to the CS3013 Home Page
Send all questions to the cs3013-ta at cs.wpi.edu mailing list.