Unformatted text preview: rate. For example, we use threads in our research to implement parallel simulations of earthquakes. The duration of the earthquake (say 60 seconds) is broken up into thousands of tiny timesteps. Each thread runs on a separate processor and models the propagation of seismic waves through some chunk of the earth, ﬁrst for timestep 1, then for timestep 2, and so on. In order to get consistent results, each thread must ﬁnish simulating timestep before the others can begin simulating timestep · ½. We guarantee this by placing a barrier between the execution of each timestep. Our barrier implementation uses a signaling variant called pthread cond broadcast that wakes up every thread currently waiting on condition variable cond.
#include <pthread.h> int pthread cond broadcast(pthread cond t *cond);
returns: 0 if OK, nonzero on error Figure 11.22 shows the code for a simple barrier package based on mutex and condition variables. The barrier package uses 4 global variables that are deﬁned in lines 2–7. The variab...
View Full Document