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 16:10
The force on a cutting tool are 2600n vertically downward and 2100 horizontal. determine the resultant force acting on the tool and the angle at which it acts.
Answers: 1
question
Engineering, 04.07.2019 18:10
Aloaded platform of total mass 500 kg is supported by a dashpot and by a set of springs of effective stiffness 72 kn/m. it is observed that when the platform is depressed through a distance x = 12.5 cm below its equilibrium position and then released without any initial velocity; it reaches its equilibrium position in the shortest possible time without overshoot. find the position and velocity of the loaded platform 0.10 sec. after its release. if a further load of 400 kg is added to the platform, find, i) the frequency of damped vibrations, and i) the amplitude of vibration after 2 complete oscillations, given that the initial amplitude is 15 cm.
Answers: 1
question
Engineering, 04.07.2019 18:10
Abrake has a normal braking torque of 2.8 kip in and heat-dissipating cast-iron surfaces whose mass is 40 lbm. suppose a load is brought to rest in 8.0 s from an initial angular speed of 1600 rev/min using the normal braking torque; estimate the temperature rise of the heat dissipating surfaces.
Answers: 3
question
Engineering, 04.07.2019 18:10
Afour cylinder four-stroke in-line engine has a stroke of 160mm, connecting rod length of 150mm, a reciprocating mass of 3kg and its firing order is 1-3-4-2. the spacing between cylinders is 100mm. i. show that the engine is in balance with regard to the primary inertia forces and primary 3. a and secondary inertia couples. li determine the out of balance secondary inertia force ii. propose ways of balancing this out of balance force and discuss the challenges that will arise
Answers: 3
You know the right answer?
In this assignment we will explore how to implement a barrier using condition variables provided by...
Questions
question
Mathematics, 07.01.2020 06:31
Questions on the website: 13722363