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, 22.06.2019 22:30
Which of the following factors would your hypothetical supervisor look at when deciding whether to test a biological material sample for dna? the amount of other evidence you have implicating a suspect in a crime the annual budget for the crime lab both of the above none of the above; you would almost always order a test
Answers: 3
question
Computers and Technology, 23.06.2019 06:40
How many nibbles can be stored in a 16-bit word?
Answers: 1
question
Computers and Technology, 24.06.2019 07:00
Selective is defined as paying attention to messages that are consistent with one’s attitudes and beliefs and ignoring messages that are inconsistent.
Answers: 1
question
Computers and Technology, 24.06.2019 17:50
You will subnet the network address 172.31.103.0/24. the network has the following requirements: · room-114 lan will require 27 host ip addresses · room-279 lan will require 25 host ip addresses · room-312 lan will require 14 host ip addresses · room-407 lan will require 8 host ip addresses how many subnets are needed in the network topology?
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, 02.06.2021 14:10
question
English, 02.06.2021 14:10
question
Mathematics, 02.06.2021 14:10
question
Business, 02.06.2021 14:10
Questions on the website: 13722361