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: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 22:00
What do the principles of notice, choice, onward transfer, and access closely apply to? a. privacyb. identificationc. retentiond. classification
Answers: 1
question
Computers and Technology, 22.06.2019 14:40
You begin your first day of responsibilities by examining the recent is security breach at gearup to get ideas for safeguards you will take. at gearup, criminals accessed the company's improperly-secured wireless system and stole customers' credit card information as well as employee social security numbers. what kind of computer crime did gearup face?
Answers: 3
question
Computers and Technology, 22.06.2019 18:40
Mariah was working on a multimedia presentation that included both video and audio files. the file was huge, and she wanted to send it to her coworker in another office. she needed to reduce the size of the file so that it could be transmitted faster. the utility she used to do this was
Answers: 2
question
Computers and Technology, 22.06.2019 23:50
List a few alternative options and input and output over the standerd keyboard and monitor. explain their functioning in details.
Answers: 2
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
Mathematics, 10.12.2021 03:00
question
Computers and Technology, 10.12.2021 03:00
question
Computers and Technology, 10.12.2021 03:00
question
Mathematics, 10.12.2021 03:00
question
Mathematics, 10.12.2021 03:00
question
Mathematics, 10.12.2021 03:00
Questions on the website: 13722359