Module 21: Problem and Solution
  Lecture 42: Multi-core ComputingInter-process Communication
 


OS Implementations

  • Busy wait is not tolerated in an OS!!
  • Bounded wait is to be ensured.
  • Solution:
    • Use sleep and wakeup to move processes from running to waiting state and waiting to ready state.
    • Maintain a queue of processes waiting and wake up processes in that order.

 

class semaphore {
private:
int value;
list<PCB> wait_list;
public:
semaphore() {
value = 0;
wait_list = list<PCB>();
}
semaphore(int a) {
value = a;
wait_list = list<PCB>();
}
void wait(void) {
value--;
if (value < 0) { wait_list.push_front(
current);
sleep();
}
}
void signal(void) {
PCB p;
value++;
if (value <=0) {
p = *(wait_list.end()); wait_list.pop_back();
wakeup(p);
}
}
}