subject

This programming question is about semaphore. create two threads t1 and t2. t1 and t2 share an integer data counter. the job of t1 is to increase the value of counter by 1 when t1 is scheduled. the job of t2 is to decrease the value of counter by 1 when t2 is scheduled. because counter is a critical section, you need to use semaphore to implement mutual exclusion between t1 and t2.here is the api you may use: sem_init: initialize an unnamed semaphoresem_wait: lock a semaphore, which is equivalent to the p operation. sem_post: unlock a semaphore, which is equivalent to the v operation. sem_destroy: destroy an unnamed semaphore. here is the basic structure of the program: int counter; //shared between t1 and t2main(){create semaphore; create t1; create t2; destroy semaphore; }thread t1 routine(){while (1){p(); increase counter by 1; output the value of counter; v(); }}thread t2 routine(){while (1){p(); decrease counter by 1; output the value of counter; v(); }}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 00:00
What season was better from fortnite?
Answers: 2
question
Computers and Technology, 23.06.2019 07:30
What is the penalty for violating section 1201 of title 17 chapter 21 of the us code
Answers: 1
question
Computers and Technology, 23.06.2019 11:50
While preforming before operation pmcs, you notice the front right tire appears slightly under-inflated. what is the proper action?
Answers: 3
question
Computers and Technology, 24.06.2019 05:50
What all vehicles has tesla inc. created over the years
Answers: 3
You know the right answer?
This programming question is about semaphore. create two threads t1 and t2. t1 and t2 share an integ...
Questions
question
English, 28.06.2019 14:00
question
Mathematics, 28.06.2019 14:00
question
Computers and Technology, 28.06.2019 14:00