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 18:00
Apunishment or the threat of punishment used to enforce conformity. select the best answer from the choices provided t f
Answers: 1
question
Computers and Technology, 23.06.2019 18:40
How does is make you feel when you're kind to others? what are some opportunities in your life to be more kind to your friends and loved ones? imagine a world where kindness has be outlawed. how would people act differently? would your day-to-day life change significantly? why or why not?
Answers: 2
question
Computers and Technology, 24.06.2019 13:10
Write a program that has a conversation with the user. the program must ask for both strings and numbers as input. the program must ask for at least 4 different inputs from the user. the program must reuse at least 3 inputs in what it displays on the screen. the program must perform some form of arithmetic operation on the numbers the user inputs. turn in your .py file as well as a screenshot of your program's output. include comments in your code to explain how it works an example program run might look like (have fun with this and be creative): ‘what is your name? ’ “josh” ‘, josh. what is your favorite color? ’ “green” ‘mine too. do you also like ice cream? ’ “no” ‘josh, how old are you? ’ “40” ‘ and how many siblings do you have? ’’ “3” ‘that means you are one of 4 kid(s). is green the favorite color of anyone else in your house? ’
Answers: 3
question
Computers and Technology, 24.06.2019 14:30
Two students are discussing the flow of electricity. student a says that voltage is a measure of the amount of electron flow in a circuit. student b says that power is the product of voltage and current. which of the following statements is correct? a. only student a is correct b. only student b is correct c. both of the two students are correct d. neither of the two students is correct
Answers: 1
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, 27.06.2019 04:30
Questions on the website: 13722361