34 lines
851 B
Modula-2
34 lines
851 B
Modula-2
DEFINITION MODULE Semaphores;
|
|
(*
|
|
Module: Processes with semaphores
|
|
Author: Ceriel J.H. Jacobs
|
|
Version: $Id$
|
|
|
|
On systems using quasi-concurrency, the only opportunities for process-
|
|
switches are calls to Down and Up.
|
|
*)
|
|
|
|
TYPE Sema;
|
|
|
|
PROCEDURE Level(s: Sema) : CARDINAL;
|
|
(* Returns current value of semaphore s *)
|
|
|
|
PROCEDURE NewSema(n: CARDINAL) : Sema;
|
|
(* Creates a new semaphore with initial level "n" *)
|
|
|
|
PROCEDURE Down(VAR s: Sema);
|
|
(* If the value of "s" is > 0, then just decrement "s".
|
|
Else, suspend the current process until the semaphore becomes
|
|
positive again.
|
|
*)
|
|
|
|
PROCEDURE Up(VAR s: Sema);
|
|
(* Increment the semaphore "s".
|
|
*)
|
|
|
|
PROCEDURE StartProcess(P: PROC; n: CARDINAL);
|
|
(* Create a new process with procedure P and workspace of size "n".
|
|
Also transfer control to it.
|
|
*)
|
|
END Semaphores.
|