Using semaphores, provide codes for processes X1, X2, X3, X4 and X5 in the following synchronization problem. Each process has a special (synchronization) point in its code. • Process X1 may cross its synchronization point unconditionally, • Process X4 has to wait for processes X3 and X1 to cross or reach their synchronization points, and only then X4 may cross its synchronization point, • Process X2 has to wait for process X1 to cross or reach its synchronization point, and only then X2 may cross its synchronization point, • Process X3 has to wait for process X4 to cross or reach its synchronization point, and only then X3 may cross its synchronization point, • Process X5 has to wait for processes X1, X3 and X4 to cross their synchronization points, and only then X5 may cross its synchronization point. Assume that each process will cross its synchronization point only once. Solution /*In the above specified conditions the process X4 depedns on completion of synchronization of X3 and X1. whereas the X3 depends on synchronisation of X4. This may create deadlock. */ package semaphoretest; import java.util.concurrent.Semaphore; public class SemaphoreTest implements Runnable { Semaphore binary = new Semaphore(1); @Override public void run() { boolean flg=false; System.out.println(\"Started\"); while(!flg) { System.out.println(\"Thread is running\"); } System.out.println(\"Stopped\"); } public static void main(String args[]) { final SemaphoreTest test = new SemaphoreTest(); Thread t1=new Thread(){ @Override public void run(){ test.mutualExclusion(); } }; Thread t2=new Thread(){ @Override public void run(){ test.mutualExclusion(); } }; Thread t3=new Thread(){ @Override public void run(){ test.mutualExclusion(); } }; Thread t4=new Thread(){ @Override public void run(){ test.mutualExclusion(); } }; Thread t5=new Thread(){ @Override public void run(){ test.mutualExclusion(); } }; t1.start(); t2.start(); t3.start(); t4.start(); t5.start(); } private void mutualExclusion() { try { binary.acquire(); //mutual exclusive region String tn=Thread.currentThread().getName(); String numberOnly= tn.replaceAll(\"[^0-9]\", \"\"); int num=Integer.parseInt(numberOnly)+1; System.out.println(\"Thread \"+num + \" is running\"); Thread.sleep(100); } catch (InterruptedException ie) { ie.printStackTrace(); } finally { binary.release(); String tn=Thread.currentThread().getName(); String numberOnly= tn.replaceAll(\"[^0-9]\", \"\"); int num=Integer.parseInt(numberOnly)+1; System.out.println(\"Thread \"+num + \" completed...!!!\"); } } }.