Shared VariablesStack Example
PACKAGE BODY stack_of_integer IS
TYPE stack_type IS ARRAY (0 TO 100) OF INTEGER;
SHARED VARIABLE stack : stack_type;
SHARED VARIABLE index : NATURAL := 0;
PROCEDURE push (what : IN INTEGER) IS
PROCEDURE pop (what : OUT INTEGER) IS
As an example of where shared variables are useful, the stack_of_integer package in this and the next slide uses a shared variable in two procedures used to maintain a stack. The designer is responsible for ensuring that no two processes call these two procedures at any one time.
The package declarative region is shown here declaring two procedures, push and pop.