The objective of this programming assignment is to give you experiences in using multiple processes and multiple threads and their inter process / thread communications. You will learn how to create processes and threads and solve some critical section problems. The programs for this Lift-simulator should include the following features.
1. There are three elevators, Lift-1, Lift-2, and Lift-3, which are servicing a 20-floor building (Floors 1 to 20). Assume that initially all lifts are in Floor 1. Each lift waits for lift requests from any floor (1 to 20) and serves one request at a time.
2. Create a file sim_input to store n requests in the following formats, for n between 50
The first number in each request represents the floor where the request is made, and the
second number is the destination floor. The two numbers are separated by a space. For
example, the first request comes from Floor 1 to go up to Floor 5, while the last request
is from Floor 20 to go down to Floor 7.
3. Create a task Lift-R that runs a function request() to get a lift request from sim_input, and puts the request into a buffer of size m. Thus there are at most m pending lift requests. The function puts a request to the buffer when there is available space. Otherwise, Lift-R is blocked waiting for available space in the buffer.
4. Create three tasks to simulate Lift-1, Lift-2, and Lift-3, each of which runs a function
lift() to perform operations of each lift. For each request, Lift-1, Lift-2, or Lift-3
removes the request from buffer, goes to the floor where the request is made, and
moves to the destination floor. Then the lift waits for the next available request if buffer
is empty, or grabs another request from buffer. Since lifts need time to go from one
floor to others, you should simulate this event; this can be done, for example, by using
sleep(t) if the time needed is t seconds. To simplify, our simulator assumes each lift
requires the same time, t seconds, for each request, for t 0. For example, the time to go
from Floor 3 to Floor 5 (2 floor-distance), is the same as the time for the lift to go from
Floor 9 to Floor 4 (5 floor-distance).