@V7 54 2 -5
@L3 COUK1247
80
@V9 0
@YCHAPTER 18 - MUSS USER MANUAL
@G@RCHAPTER 18 - SEMAPHORES@G
@V10 1 9 248
@T% 10
@BThe primary synchronisation mechanism
in MUSS is its message system.  This allows
collaborating processes to be distributed across
a network.  However, it is possible for
processes in the same machine to share
segments, providing the memory management hardware allows
multiple virtual addresses to be associated with the
same physical address.
The common segments are one
example of this, also when the underlying hardware
architecture is suitable, two or more processes may open
the same file and share one physical copy.  Thus some special
applications may run as
multiprocess systems with the processes
communicating through shared store.  The following set of
commands are provided, in order to facilitate the
synchronisation of these processes.  They will
not normally be present in the standard general purpose
MUSS system, but can be compiled into any special
purpose system which require them.
@S218.1 COMMANDS
@
@
(1) @JCREATE.SEMAPHORE(I)
@BThis procedure creates a semaphore with the
number given by P1 for use in the current
process.
Normally up to 8 semaphores may be used as P1 is
taken modulo 8.
@
@
(2) @JPASS.SEMAPHORE(I,I,I)
@BThis procedure is used to enable a semaphore
of the current process to be made
available to any process created by the
current process.  P1 gives the semaphore number
in the current process, P2 gives its number in
the recipient process and P3 gives the SPN
of the recipient process.  When a semaphore
has been passed in this way the recipient
and creating processes may both use the
P and V operations described below.
@
@
(3) INIT.SEMAPHORE(I,I)
@BThis command may only be issued by the
processes which created the semaphore P1.  It
initialises the semaphore value to P2 and sets
its wait queue empty.
@
@
(4) @JP.SEMAPHORE(I)
@BThis command performs the Dijkstra "P" operation
on the semaphore P1@
@Q 3
@T% 10
@
  i.e.%value(P1) := value(P1)-1@
%WHILE P1 < 0 WAIT.@
@
@
Thus the current process may be placed in
a waiting state until some other processes cause the
semaphore value to become @O>@O 0.  Any
number of processes may be waiting on the same
semaphore and they are ordered in arrival order.
@
@
(5) @JV.SEMAPHORE(I)
@BThis command performs the Dijkstra "V" operation on the
semaphore P1@
@Q 3
@
  i.e.%value(P1) := value(P1)+1@
%IF P1 @O<@O 0 THEN FREE FIRST WAITING PROCESS.@
@S218.2 RELEASING SEMAPHORES
@BWhen any process ends which is connected to a semaphore the
number of users of the semaphore is decremented by 1.  If there
are other processes still connected
to the semaphore it will remain in operation.  If the terminating
process was in the P state a V operation will be forced.  When the
terminating process is the only process connected to a
semaphore it will cease to exist and the data
structures associated with it will be released.
@F
