Lecture 15 - Midterm Review

Some tips:

What will be covered:

  1. Introduction/History of OS's
  2. What is an OS? Resource Management (Asgn1) and Priviledge
  3. Independent Threads of Control (Asgn2) and Concurrency
  4. More on Synchronization Mechanisms (critical section, scheduling, etc.), Deadlock (Asgn3)
  5. Architecture of IO Systems

Reviewed Topics

Timesharing is when you share time between threads, specifically:

Also looking at question 35 on the MT, we found that making lwp_fork is impossible to make since if you just copied the stacks, the pointers (memory addresses) would point to the original stack, which isn't the intended idea.

For question 36, you can do:

typedef int Semaphore;

Semaphore s = 1;

void DOWN(Semaphore *s)
{
	while(*s == 0) lwp_yield(); // wait for your turn
	*(s)--; // decrement
}

void UP(Semaphore *s)
{
	*(s)++; // increment. Ensures its non-zero. 
}

The better way would be to Queue up your thread id, then to only yield while it is not your turn. Change UP to be:

//...
void DOWN(Semaphore *s)
{
	enqueue(lwp_gettid(), *q); // stick yourself on the queue
	while(*s != 0 || head(*q) != lwp_gettid()) lwp_yield(); // wait for the semaphore OR it's not your turn. 
	*(s)--; // decrement
}
//...