[ shared ] variable identifier_list : subtype_indication [ := expression ] ;
identifier {, identifier }
[ resolution_function_ name ] type_mark [ constraint ]
Shared variables declarations are allowed only in the declarative part of entities, architectures, packages, package bodies and blocks. Shared variables declarations must not be used in processes and subprograms.
More than one process can access shared variables. If several processes access a given shared variable in the same simulation cycle, the sequence of accesses is not prescribed. It is neither the actual value of the variable after the simulation cycle nor the different values of the variable read within the simulation cycle are deterministic. See example below.
The variable count of the type positive is declared.
VARIABLE count : positive ;
The variables index and memory are declared as subtypes of the types integer and bit_matrix .
VARIABLE index : integer RANGE 0 TO 99 := 0 ; VARIABLE memory : bit_matrix ( 0 TO 7, 0 TO 1023 ) ;
VARIABLE address_bus : bit8 := "00110110" ; VARIABLE integer_address : integer := 2**nb_bit - 1 ; VARIABLE bittab : bit_vector (1 TO 9) := ( 1 TO 3 => '0', 7 | 9 => 'Z', OTHERS => '1' ) ; VARIABLE tab : table_type( 0 TO 4 ) := ( 2, 3, 4, -2, 0 ) ;
An example for the non-deterministic of using shared variables :
A shared variable which is manipulated by two processes is declared in the architecture.
It is not prescribed, whether
ARCHITECTURE beh OF sv_example IS SHARED VARIABLE counter : integer RANGE 0 TO 1 := 0 ; BEGIN p1: PROCESS BEGIN counter := counter + 1 ; wait ; END PROCESS p1; p2: PROCESS BEGIN counter := counter - 1; wait ; END PROCESS p2 ; END ARCHITECTURE beh;