Ada Programming/Pragmas/Shared

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Ada. Time-tested, safe and secure.
Ada. Time-tested, safe and secure.
pragma Shared (local_name);

Summary[edit | edit source]

This language feature is deprecated since Ada 95.

Shared is an Ada 83 representation pragma equivalent to Atomic.[1] However, it can only be applied to variables, whereas Atomic can also be used with types.

It was removed from the language in Ada 95 for several reasons:

  • it was not properly defined[2]
  • it couldn't be applied to arrays[2]
  • the name Shared was confusing[3]

In Ada 95 pragma Shared was replaced by pragma Atomic, Volatile, Atomic_Components, and Volatile_Components.

Portability[edit | edit source]

Shared is a standard pragma of Ada 83, so it must be implemented by all Ada 83 compilers. It is obsolescent in successive versions of the language, but it is equivalent to pragma Atomic and thus it is usually implemented by Ada 95 compilers for compatibility.[4]

Example[edit | edit source]

type Device_Status :  Status_Register;
pragma Shared (Device_Status);

Incorrect usage[edit | edit source]

It is usually unsafe to use shared variables for tasking.[5]

See also[edit | edit source]

Wikibook[edit | edit source]

Ada 83 Reference Manual[edit | edit source]

Ada 95 Rationale[edit | edit source]

Ada 83 Rationale[edit | edit source]

Ada 83 Quality and Style Guide[edit | edit source]

References[edit | edit source]

  1. Robert Dewar (1996-02-17). "pragma Shared (was Ada is almost ....)". comp.lang.ada. (Web link). Retrieved on 2008-05-28. "pragma Atomic is QUITE different from pragma Volatile. pragma Atomic in Ada is essentially identical to pragma Shared in Ada 83. pragma Volatile in Ada is essentially identical to volatile in C, and is a feature that is not available in Ada 83."
  2. a b Laurent Guerby (1995). "C.5 Shared Variable Control". Ada 95 Rationale. Intermetrics. The pragma Shared was quite weak. The semantics were only defined in terms of tasks, and not very clearly. This made it inadequate for communication with non-Ada software or hardware devices. Moreover, it could be applied only to a limited set of objects. For example, it could not be applied to a component of an array. {{cite book}}: |access-date= requires |url= (help); External link in |chapter= (help); Unknown parameter |month= ignored (help)
  3. "C.6 Shared Variable Control". Annotated Ada 95 Reference Manual. Retrieved 2008-05-28. Pragma Atomic replaces Ada 83's pragma Shared. The name Shared was confusing, because the pragma was not used to mark variables as shared. {{cite book}}: Unknown parameter |chapterurl= ignored (|chapter-url= suggested) (help)
  4. "Implementation Defined Pragmas". GNAT Pro Reference Manual. AdaCore. Retrieved 2008-05-28. This pragma is provided for compatibility with Ada 83. The syntax and semantics are identical to pragma Atomic. {{cite book}}: Unknown parameter |chapterurl= ignored (|chapter-url= suggested) (help)
  5. "7.4.7 Shared Variables and Pragma Shared". Ada 83 Quality and Style. Software Productivity Consortium, Inc. Do not use shared variables as a task synchronization device. Use pragma Shared only when you are forced to by run time system deficiencies. {{cite book}}: |access-date= requires |url= (help); External link in |chapter= (help)