Dana Vrajitoru
B424/B524 Parallel and Distributed Programming

B424/B524 Homework 4

Due date: Thursday, September 24, 2020.

Barrier example.

The following files contain an implementation of the Barrier using conditional variables in the pthread library and the testing code. You can use it as a starting point for this homework.

red_barrier.h
red_barrier.cc
main.cc
Makefile

Ex. 1 Single Roller Coaster Car Problem

Let's suppose that there are n passengers and one roller coaster car. The passengers repeatedly wait to take rides in the car, which holds C passengers. However, the car can go around the track only when it is full. The car takes the same number of seconds (T) to go around the track each time it fills up. After getting a ride, each passenger wanders around the amusement park for a random amount of time before returning to the roller coaster for another ride.

Write a program using pthreads to simulate this problem. The program should ask for n and C, then generate n passenger threads. Implement a function

void Ride(int C, int id);

using a conditional variable. This function should be similar to the function Barrier discussed in class. Beside the functionality of the barrier, this function should print all the passenger ids that get a ride together and make sure that no more than C passengers get in the car in one ride.

We will assume that for this problem, n will be a multiple of C. You can implement either a version where each person gets a given number of rides, or where there are a given number of rides on the whole.

Homework Submission

Upload the source files to Canvas, in Assignment, Homework 4.