Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!unmvax!ncar!boulder!sunybcs!bingvaxu!leah!itsgw!steinmetz!uunet!dalcs!aucs!831059l
From: 831059l@aucs.UUCP (Langlois)
Newsgroups: comp.lang.smalltalk
Subject: Re: Differencs between Smalltalk/V and Smalltalk/V286
Message-ID: <1428@aucs.UUCP>
Date: 5 Dec 88 23:30:01 GMT
References: <1424@aucs.UUCP>
Reply-To: 831059l@aucs.UUCP (Langlois)
Organization: School of Computer Science, Acadia Univ., Nova Scotia
Lines: 121


	As so often is the case, one's first interpretation and solution
for a problem is not correct. As you'll will shortly see, my mistake was 
understandable because of the similarity of the output from my simulation.
But, nevertheless, it was still a mistake. The simulation is Boats 1 from
G. M. Birtwistle's book "Discrete Event Modelling on Simula" (DEMOS). For
those unfamaliar, it is a model of a port system with 2 jetties and 3 tugs.
The boats, Boat 1, Boat 2, and Boat 3, arrive at times 0.0, 1.0, and 9.7
respectively. The actions of a boat are expressed in a smalltalk method
called actions and are as follows:

actions
    self acquire: 1 ofResource: 'JETTIES'.
    self acquire: 2 ofResource: 'TUGS'.
    self hold: 2.0.
    self release: 2 ofResource: 'TUGS'.
    self hold: 13.9.
    self acquire: 1 ofResource: 'TUGS'.
    self hold: 2.0.
    self release: 1 ofResource: 'TUGS'.
    self release: 1 ofResource: 'JETTIES'

When I put the statement Processor yield in the main loop of my simulation
I thought I had solve the problem because with this statement, the    
simulation run as follows:

0.0 Boat 1      schedules Boat 1 at 0.0
0.0 Boat 2      schedules Boat 2 at 1.0
0.0 Boat 3      schedules Boat 3 at 9.7
0.0 Boat 1      seizes 1 of JETTIES
0.0 Boat 1      seizes 2 of TUGS
0.0 Boat 1      holds for 2.0, until 2.0
1.0 Boat 2      seizes 1 of JETTIES
1.0 Boat 2      awaits 2 of TUGS
2.0 Boat 1      releases 2 to TUGS
2.0 Boat 1      holds for 13.9, until 15.9
9.7 Boat 2      seizes 2 of TUGS
9.7 Boat 2      holds for 2.0, until 11.7
11.7 Boat 2     releases 2 to TUGS
11.7 Boat 2     holds for 13.9, until 25.6
---------- etc. -------------

	The first problem occurs when Boat 1 releases 2 TUGS at 2.0. Boat 2
is waiting for 2 of TUGS and when Boat 1 releases 2 it should seize them
and then continue. Instead, Boat 3 arrives and sets the time to 9.7, the 
time when it was scheduled to arrive. From then on, it's a mess and there is
no point of continuing. 
	Now the problem is when the boats are created, they are given the same
priority as the process that was created to execute the selected text. So, 
Boat 3 which has been waiting the longest gets a chance to go before Boat 2
which is waiting for 2 of TUGS. In Smalltalk/V, this wasn't a problem as it
seemed that the selected text wasn't a process or it was created with a lower 
priority than the processes it created. So, in Smalltalk/V the boats where
initialized as follows:

initialize
    eventTime := nil.
    queuedFor := 0.
    waitingSemaphore := Semaphore new.
    processOf := [waitingSemaphore wait.
                  self actions] fork

	In Smalltalk/V286 the boats are given the same priority and hence
the problem. To solve the problem, I changed the creation of a boat as
follows:

initialize
    eventTime := nil.
    queuedFor := 0.
    waitingSemaphore := Semaphore new.
    processOf := [waitingSemaphore wait.
                  self actions] forkAt: CreationPriority

where CreationPriority is a class variable set when a simulation starts to
the priority of the initiating Process + 1. Now I'm not so sure I like the
solution but it works as shown next:

0.0 Boat 1      schedules Boat 1 at 0.0
0.0 Boat 2      schedules Boat 2 at 1.0
0.0 Boat 3      schedules Boat 3 at 9.7
0.0 Boat 1      seizes 1 of JETTIES
0.0 Boat 1      seizes 2 of TUGS
0.0 Boat 1      holds for 2.0, until 2.0
1.0 Boat 2      seizes 1 of JETTIES
1.0 Boat 2      awaits 2 of TUGS
2.0 Boat 1      releases 2 to TUGS
2.0 Boat 2      seizes 2 of TUGS
2.0 Boat 2      holds for 2.0, until 4.0
2.0 Boat 1      holds for 13.9, until 15.9
4.0 Boat 2      releases 2 to TUGS
4.0 Boat 2      holds for 13.9, until 17.9
9.7 Boat 3      awaits 1 of JETTIES
15.9 Boat 1     seizes 1 of TUGS
15.9 Boat 1     holds for 2.0, until 17.9
17.9 Boat 2     seizes 1 of TUGS
17.9 Boat 2     holds for 2.0, until 19.9
17.9 Boat 1     releases 1 to TUGS
17.9 Boat 1     releases 1 to JETTIES
17.9 Boat 3     seizes 1 of JETTIES
17.9 Boat 3     seizes 2 of TUGS
17.9 Boat 3     holds for 2.0, until 19.9
19.9 Boat 2     releases 1 to TUGS
19.9 Boat 2     releases 1 to JETTIES
19.9 Boat 3     releases 2 to TUGS
19.9 Boat 3     holds for 13.9, until 33.8
33.8 Boat 3     seizes 1 of TUGS
33.8 Boat 3     holds for 2.0, until 35.8
35.8 Boat 3     releases 1 to TUGS
35.8 Boat 3     releases 1 to JETTIES

	I realize that multliprocessing was added to Smalltalk/V but a
Goodies disk but I wish the writers of V 286 would have consulted the
creators of the Goodies disk or had of at least inclueded an explanation
of the differences somewhere, on disk or in the manual. The is a file
showing the differences, but as far as differences in multiprocessing
there was nada.

Steven Langlois     UUCP:     {uunet|watmath|utai|garfield}!dalcs!aucs!831059l
Acadia University   BITNET:   Steven@Acadia
Wolfville, NS       Internet: Steven%Acadia.BITNET@CUNYVM.CUNY.EDU
CANADA  B0P 1X0