- Thread 2 having function to print 1 to 10 finishes before Thread 1 having function to print 10 to 20
- Thread 1 finishes before Thread 3 having function to print 20 to 30
- Use semaphore(s) to enforce these sychronization rules by adding P() and V() calls
- Finally, you must include sem create calls in suitable places to create and initialize the semaphores.
- Use sem create() calls show the intial semaphore value for each newly created semaphore.
- Do not use any synchronization primitives or techniques other than sempahores.
- code.c is the main file which achieve the goal. without_sem.c is used to illustrate the problem which arises when we don't use semaphores
gcc compiler
- using semaphores
$ gcc code.c -lpthread
- without using semaphores
$ gcc without_sem.c -lpthread
$ ./a.out
Lovely Professional University
LinkedIn: Debasish Dash ·