subject
Engineering, 18.11.2019 21:31 jujurae03

In this assignment we will explore how to implement a barrier using condition variables provided by the pthread library. a barrier is a point in an application at which all threads must wait until all other threads reach that point too. condition variables are a sequence coordination technique similar to xv6's sleep and wakeup. submit your solutions before the beginning of the next lecture to the submission web site. download barrier. c and compile it on your laptop or athena machine: $ gcc -g -o2 -pthread barrier. c $ ./a. out 2 assertion failed: (i == t), function thread, file barrier. c, line 55. the 2 specifies the number of threads that synchronize on the barrier ( nthread in barrier. c). each thread sits in a tight loop. in each loop iteration a thread calls barrier() and then sleeps for some random number of microseconds. the assert triggers, because one thread leaves the barrier before the other thread has reached the barrier. the desired behavior is that all threads should block until nthreads have called barrier. your goal is to achieve the desired behavior. in addition to the lock primitives that you have seen before, you will need the following new pthread primitives (see man pthreads for more detail): pthread_cond_wait(& cond, & mutex); // go to sleep on cond, releasing lock mutex pthread_cond_broadcast(& cond); // wake up every thread sleeping on cond pthread_cond_wait releases the mutex when called, and re-acquires the mutex before returning. we have given you your job is to implement barrier() so that the panic won't occur. we've defined struct barrier for you; its fields are for your use. there are two issues that complicate your task: you have to deal with a succession of barrier calls, each of which we'll call a round. bstate. round records the current round. you should increase bstate. round when each round starts. you have to handle the case in which one thread races around the loop before the others have exited the barrier. in particular, you are re-using bstate. nthread from one round to the next. make sure that a thread that leaves the barrier and races around the loop doesn't increase bstate. nthread while a previous round is still using it. test your code with one, two, and more than two threads.

ansver
Answers: 2

Another question on Engineering

question
Engineering, 04.07.2019 18:10
Awall of 0.5m thickness is to be constructed from a material which has average thermal conductivity of 1.4 w/mk. the wall is to be insulated with a material having an average thermal conductivity of 0.35 w/mk so that heat loss per square meter shall not exceed 1450 w. assume inner wall surface temperature of 1200°c and outer surface temperature of the insulation to be 15°c. calculate the thickness of insulation required.
Answers: 3
question
Engineering, 04.07.2019 18:20
Determine the damped natural frequencies and the steady state response of a decoupled damped forced two degrees of freedom system. 10ä1 + 2q1 20q1 10 cos t; 10q2 +4q2 + 40q2 10 cos t
Answers: 3
question
Engineering, 04.07.2019 18:20
Find the kinematic pressure of 160kpa. for air, r-287 j/ kg k. and hair al viscosity of air at a temperature of 50°c and an absolute (10 points) (b) find the dynamic viscosity of air at 110 °c. sutherland constant for air is 111k
Answers: 3
question
Engineering, 04.07.2019 18:20
Apiston-cylinder device contains 0.1 m3 of liquid water and 0.9 m3 of water vapor in equilibrium at 800 kpa. heat is transferred at constant pressure until the temperature of water reaches 350 °c. determine (a) the quality of water at the initial state (b) the work associated with this process, (c) the heat associated with this process.
Answers: 2
You know the right answer?
In this assignment we will explore how to implement a barrier using condition variables provided by...
Questions
question
Geography, 17.08.2019 16:10
question
Mathematics, 17.08.2019 16:10
Questions on the website: 13722361