HP Fortran Programmer's Guide (September 2007)

Controlling data storage
Sharing data among programs
Chapter 3 111
! The shared memory segment is destroyed when this program halts.
END
IMPORTANT In the example above, you must use +U77 to access the correct sleep in the
Fortran library. If you use +U77, the line above:
CALL sleep (%VAL(1))
should instead read:
CALL sleep (1)
Example 3-4 wake_up.f90
PROGRAM main
! This program, wake_up.f90, should be run just after its
! companion, go_to_sleep.f90, starts to execute but in a
! separate process. The $HP$ SHARED_COMMON directive
! enables both programs to share the same memory.
! Directive puts the common block in shared memory.
$SHARED_COMMON KEY=’scb1’ /shared_common/
LOGICAL :: alarm
CHARACTER(LEN=8) :: message
! Declare a named common block for shared memory. It must
! be laid out n exactly the same way in both programs.
COMMON /shared_common/ alarm, message
! Write to message, sleep reads it.
message = "I'm up!"
! Set alarm to wake up sleep.
alarm = .TRUE.
! The shared memory segment will now be detached.
! However, because go_to_sleep is still running,
! the segment will still be present in memory until
! it stops executing, too.
END
Following are the command lines to compile each program:
$ f90 -o go_to_sleep go_to_sleep.f
$ f90 -o wake_up wake_up.f