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, 03.07.2019 14:10
Amass of m 1.5 kg of steam is contained in a closed rigid container. initially the pressure and temperature of the steam are: p 1.5 mpa and t 240°c (superheated state), respectively. then the temperature drops to t2= 100°c as the result of heat transfer to the surroundings. determine: a) quality of the steam at the end of the process, b) heat transfer with the surroundings. for: p1.5 mpa and t 240°c: enthalpy of superheated vapour is 2900 kj/kg, specific volume of superheated vapour is 0. 1483 m/kg, while for t 100°c: enthalpy of saturated liquid water is 419kj/kg, specific volume of saturated liquid water is 0.001043m/kg, enthalpy of saturated vapour is 2676 kj/kg, specific volume of saturated vapour is 1.672 m/kg and pressure is 0.1 mpa.
Answers: 3
question
Engineering, 03.07.2019 14:10
Line joining liquid phase with liquid and solid phase mixture is known as: a) liquidus b) solidus c) tie line d) none of the mentioned
Answers: 2
question
Engineering, 03.07.2019 15:10
Apiston-cylinder with a volume of 0.25 m3 holds 1 kg of air (r 0.287 k/kgk) at a temperature of 100 c. heat transfer to the cylinder causes an isothermal expansion of the piston until the volume triples. how much heat is added to the piston-cylinder?
Answers: 3
question
Engineering, 04.07.2019 18:10
The filament of an incandescent lamp has a temperature of 2000k. calculate the fraction of radiation emitted in the visible light band if the filament is approximated as blackbody
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, 30.08.2020 15:01
Questions on the website: 13722363