The file sellers.scm contains all the code you need to run the simulation. It includes the make-serializer procedure that you will need. It redefines sleep so that we can run the simulation faster for testing. The speed is controlled by the global variable sleep-factor.
To run the simulation, load sellers.scm into DrScheme and run (test). If some of the ticket sellers don't sell any tickets, increase the value of global variable sleep-factor. If it takes more than a few seconds for (test) to run, make sleep-factor smaller. (On Strauss, sleep-factor probably should be about 1000. On my laptop with 700MHz processor, a value of 3000 is about right.)
When (test) is run, the global variable *SEATS-LEFT* is set to 100, ten ticket sellers are created by calls to make-ticket-seller and run as concurrent threads. The calls to sleep with a random argument assures that the threads proceed in an unpredictable way so that they don't update *SEATS-LEFT* properly until you fix the problem.
2. You are to change the definition of make-ticket-sellers so that the ticket sellers only sell 100 tickets and so that their reports don't get mixed up. Do not change any other code in sellers.scm. You will have to add a line or two of additional code besides changing the definition of makep-ticket-seller. Here is the definition of make-ticket-seller:
(define (make-ticket-seller name)
(let ((total-tickets-sold 0))
(define (sell)
(sleep (random 2)) ;sleep up to two seconds until customer arrives
(if (customer-order *SEATS-LEFT*)
(begin (set! *SEATS-LEFT* (- *SEATS-LEFT* 1)) ;record the sale globally
(set! total-tickets-sold (+ total-tickets-sold 1)) ; local record
(sell)) ;continue selling
(print-tickets-sold name total-tickets-sold)
))
sell))
Note that there are two areas where serialization is necessary. One is where
ticket seller accesses *SEATS-LEFT* and updates it, and the other
is where it makes its report about how many tickets it has sold. You have to
make changes that serialize both areas. You should serialize as little code
as you can, however. You will want to create only one serializer and then
use it in the definition of make-ticket-seller so that all the
serialized procedures use the same mutex.
3. Submit to the Automated Tester only the definitions of make-serializer and make-mutex, followed by the code that creates the serializer, and your version of make-ticket-seller. Since random numbers are generated during the testing, you should submit your solution to the tester several times and get a PASS each time before pressing the Confirm button once to make your submission official.