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