Engineering
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.

answer
Answers: 2

Other questions on the subject: Engineering

image
Engineering, 04.07.2019 18:10, aaliyah80
The drive force for diffusion is 7 fick's first law can be used to solve the non-steady state diffusion. a)-true b)-false
Answers: 1
image
Engineering, 04.07.2019 19:20, praveen35301
Amass-spring-viscous damper system of mass 3 kg has a frequency of 100 rad/s and is critically damped. its initial conditions are x(0)-3 mm and (0)-2.3 m/s. does the system overshoot its equilibrium position? prove your answer
Answers: 1
image
Engineering, 06.07.2019 02:30, jayjay5246
Air (c-1.006 kj/kg. k, r-0.287 kj/kg. k) enters a nozzle steadily at 280 kpa and 77°c with a velocity of 50 m/s and exits at 85 kpa and 320 m/s. the heat losses from the nozzle to the surrounding medium at 20°c are estimated to be 3.2 kj/kg. determine (a) the exit temperature and (b) the total entropy change for this process. solve this problem using constant specific heats.
Answers: 1
image
Engineering, 06.07.2019 03:10, Bloom247
List and describe the attached tools in boxford cnc milling machine? and how many tools were used in your projects explain them?
Answers: 3
Do you know the correct answer?
In this assignment we will explore how to implement a barrier using condition variables provided by...

Questions in other subjects:

Konu
Mathematics, 06.10.2021 14:00
Konu
Mathematics, 06.10.2021 14:00