HP Fortran Programmer's Guide (B3908-90031; September 2011)

Controlling data storage
Sharing data among programs
Chapter 3114
The following two examples illustrate these concepts.
Example 3-3 go_to_sleep.f90
PROGRAM main
! This program, go_to_sleep.f90, and its companion, wake_up.f90,
! share data in a common block, using the $HP$ SHARED_COMMON
! directive. Execute this program first. After it starts to
! execute, use ipcs(1) to confirm that a shared memory segment
! has been created. In a separate process, run wake.f90.
! When it executes, it assigns to alarm, ending this program.
LOGICAL :: alarm
CHARACTER(LEN=8) :: message
! Declare a common block, shared_data, for sharing among
! multiple, simultaneously executing programs. Each program
! that shares the common block must reference it by the same
! key, 'scb1'.
!$HP$ SHARED_COMMON KEY=’scb1’ /shared_data/
! Declare a common block with two variables: alarm and message.
! when alarm is set by wake_up.f90, this program breaks out
! of the DO loop, prints message (which wake_up.f90 has
! written to), and exits.
COMMON /shared_data/ alarm, message
alarm = .FALSE.
! Wait for alarm to be set...
DO WHILE (alarm .EQ. .FALSE.)
! sleep(1) is an HP-UX system call that suspends a process
! for the number of seconds specified by the argument.
! The %VAL function tells Fortran that sleep expects its
! argument to be passed by value.
CALL sleep(%VAL(1))
END DO
! Message from wake.f90:
PRINT *, message
! 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: