Professional Documents
Culture Documents
Platform Technologies
Name:
JEREMY A DANZALAN
Program/Course: PT101 BSIT-2A
Guide Question/s
1. Draw the process of Synchronization of the following . You can also provide screen
shots if needed.
a. Binary Semaphore
Code
Struct Semaphore{
if (mutex.value == ){
mutex.value =0;
}
else {
processes.push(P);
sleep( );
}
}
Signal ( Semaphore mutex){
If (mutex.processes is empty){
Mutex.value =1;
}
Else {
process p= processes.pop( );
wakeup(p);
}
}
b. Counting Semaphore
Struct Semaphore( ){
int value;
Queue<process> processes;
}
wait (Semaphore s){
s.value -=1;
if (s.value< 0{
processes.push(p);
block( );
}
else {
return;
}
}
c. Monitor
Procedure p1{….}
Procedure p2{….}
wait ( mutex);
if (next_count >0)
signal (next);
else
signal(mutex);
monitor DiningPhilosophers
{
Void putdown(int i) {
state[i] =THINKING;
test((i +4) %5);
test((i+1) %5);
}
Void test(int i) {
if ((state[(i+ 4) %5] != EATING) &&
(state [i] == HUNGRY) &&
(state[(i +1) %5] != EATING)) {
state[i] = EATING;
self[i].signal( );
}
}
initialization_code( ) {
for ( int I =0; i <5; i++)
state[i] =THINKING;
}
}