In a past prac. exam for an algorithm course I'm doing is the challenge below, and their are no solutions but it seems like a really interesting one to solve. Can someone please help and point me in the right direction, I would like to try this on my own, but please give some assistance.
I need to write a multithreaded program (using pthreads, code must run on linux, i'm using ubuntu maverick) to simulate a shuttle that operates on a circuit, stopping at the stadium, and the city center only.
1) The shuttle waits until the occupants signal for it to move to the other stop.
2) The people waiting board the shuttle, and when the last person is on they signal that the bus should begin moving.
3)The passengers exit, and when the last passenger has left, the other passengers board, and signal to leave for next stop.
4) If their are no passengers waiting, shuttle waits.
5) The shuttle can take a max of 12 people.
6) The shuttle takes 2 time units to move between stops.
Use a thread for each stop to indicate when passengers arrive.
Generate a random number between 1 and 10 to indicate the time units when a passenger arrives.
If there are more than 14 people waiting the other people elect to use the stairs.
Output a trace for twenty movements of the shuttle: ie.
Shuttle waits at stadium
Shuttle moves from stadium to city center with 8 people.
Shuttle waits at city center
Shuttle moves from city center to stadium with 10 people.