Next: Code Generation for Array Aggregates, Previous: GNAT Implementation of Tasking, Up: Implementation of Specific Ada Features [Contents][Index]
GNAT fully implements the
pragma
Shared_Passive
for
the purpose of designating shared passive packages.
This allows the use of passive partitions in the
context described in the Ada Reference Manual; i.e., for communication
between separate partitions of a distributed application using the
features in Annex E.
However, the implementation approach used by GNAT provides for more extensive usage as follows:
This allows separate programs to access the data in passive partitions, using protected objects for synchronization where needed. The only requirement is that the two programs have a common shared file system. It is even possible for programs running on different machines with different architectures (e.g., different endianness) to communicate via the data in a passive partition.
The data in a passive package can persist from one run of a program to another, so that a later program sees the final values stored by a previous run of the same program.
The implementation approach used is to store the data in files. A separate stream file is created for each object in the package, and an access to an object causes the corresponding file to be read or written.
The environment variable SHARED_MEMORY_DIRECTORY
should be
set to the directory to be used for these files.
The files in this directory
have names that correspond to their fully qualified names. For
example, if we have the package
package X is pragma Shared_Passive (X); Y : Integer; Z : Float; end X;
and the environment variable is set to /stemp/
, then the files created
will have the names:
/stemp/x.y /stemp/x.z
These files are created when a value is initially written to the object, and the files are retained until manually deleted. This provides the persistence semantics. If no file exists, it means that no partition has assigned a value to the variable; in this case the initial value declared in the package will be used. This model ensures that there are no issues in synchronizing the elaboration process, since elaboration of passive packages elaborates the initial values, but does not create the files.
The files are written using normal Stream_IO
access.
If you want to be able
to communicate between programs or partitions running on different
architectures, then you should use the XDR versions of the stream attribute
routines, since these are architecture independent.
If active synchronization is required for access to the variables in the
shared passive package, then as described in the Ada Reference Manual, the
package may contain protected objects used for this purpose. In this case
a lock file (whose name is ___lock
(three underscores)
is created in the shared memory directory.
This is used to provide the required locking semantics for proper protected object synchronization.