1 (* Library module defined by the International Standard
2 Information technology - programming languages
3 BS ISO/IEC 10514-1:1996E Part 1: Modula-2, Base Language.
5 Copyright ISO/IEC (International Organization for Standardization
6 and International Electrotechnical Commission) 1996-2021.
8 It may be freely copied for the purpose of implementation (see page
9 707 of the Information technology - Programming languages Part 1:
10 Modula-2, Base Language. BS ISO/IEC 10514-1:1996). *)
12 DEFINITION MODULE Semaphores
;
14 (* Provides mutual exclusion facilities for use by processes. *)
19 PROCEDURE Create (VAR s
: SEMAPHORE
; initialCount
: CARDINAL );
20 (* Creates and returns s as the identity of a new semaphore that
21 has its associated count initialized to initialCount, and has
22 no processes yet waiting on it.
25 PROCEDURE Destroy (VAR s
: SEMAPHORE
);
26 (* Recovers the resources used to implement the semaphore s,
27 provided that no process is waiting for s to become free.
30 PROCEDURE Claim (s
: SEMAPHORE
);
31 (* If the count associated with the semaphore s is non-zero,
32 decrements this count and allows the calling process to
33 continue; otherwise suspends the calling process until
37 PROCEDURE Release (s
: SEMAPHORE
);
38 (* If there are any processes waiting on the semaphore s,
39 allows one of them to enter the ready state; otherwise
40 increments the count associated with s.
43 PROCEDURE CondClaim (s
: SEMAPHORE
): BOOLEAN;
44 (* Returns FALSE if the call Claim(s) would cause the calling
45 process to be suspended; in this case the count associated
46 with s is not changed. Otherwise returns TRUE and the
47 associated count is decremented.