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
Steel is coated with a thin layer of ceramic to protect against corrosion. what do you expect to happen to the coating when the temperature of the steel is increased significantly? explain.
Answers: 1
question
Engineering, 04.07.2019 18:10
Apump is used to circulate hot water in a home heating system. water enters the well-insulated pump operating at steady state at a rate of 0.42 gal/min. the inlet pressure and temperature are 14.7 lbf/in.2, and 180°f, respectively; at the exit the pressure is 60 lbf/in.2 the pump requires 1/15 hp of power input. water can be modeled as an incompressible substance with constant density of 60.58 lb/ft3 and constant specific heat of 1 btu/lb or. neglecting kinetic and potential energy effects, determine the temperature change, in °r, as the water flows through the pump.
Answers: 1
question
Engineering, 04.07.2019 18:10
Acompressor receives the shaft work to decrease the pressure of the fluid. a)- true b)- false
Answers: 3
question
Engineering, 04.07.2019 18:10
During a steady flow process, the change of energy with respect to time is zero. a)- true b)- false
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
English, 21.02.2021 18:20
question
Social Studies, 21.02.2021 18:20
question
Social Studies, 21.02.2021 18:20
question
Mathematics, 21.02.2021 18:20
question
Chemistry, 21.02.2021 18:20
question
Mathematics, 21.02.2021 18:20
question
Chemistry, 21.02.2021 18:20
Questions on the website: 13722360