User`s guide

Cray XMT Programming Environment Users Guide
In the previous example, a new readable and writable file is created by using the
open system call with the O_RDWR and O_CREAT flags. The fd file descriptor
is allocated and refers to the file. The fd is specified as an argument to the mmap
system call and identifies the memory region. SHARED_SIZE specifies the size of
the memory region to allocate and map into the caller's address space. PROT_READ
| PROT_WRITE specifies that the caller has both read and write permissions to the
memory. MAP_SHARED specifies that this is a shared memory region. MAP_ANON
specifies that the operating system should allocate physical memory that is not backed
up to a file. The mmap system call returns a pointer to the starting virtual address at
which the memory was mapped. The data in the memory region is initialized to zeros
and the memory state is initialized to full.
The physical memory associated with a shared memory region is normally
freed when the last process that was sharing the memory unmaps the memory
from its address space. The memory is unmapped either by an explicit call to
the unmap system call or automatically upon termination of the process. The
persist_rememd function causes the remember daemon to create a mapping to
the shared memory region. This preserves the shared memory region even after all
other user processes have unmapped the region. The data is preserved only until
the system reboots, at which time all data that was in the shared memory region is
lost. The persist_rememd function will remember the file name and size of the
memory region across reboots and will automatically reallocate the shared memory
region upon reboot; the data in the shared memory region is initialized to contain
zeros and the state is initialized to full. For more information, see the rememd(8)
man page.
Additionally, programs that use synchronization must add calls to the
mta_lock_thread and mta_set_thread runtime functions, as shown in the
following example.
mta_lock_thread(); //Set retry > 0
mta_set_thread_datablocked_retry(MAXINT); //Sets retries = INF
The mta_lock_thread function locks a thread to its stream so that the thread
does not block and release the stream when it takes a retry limit exception. The
mta_set_thread function sets the retry limit to the maximum value. The result
of calling these two functions is to cause a thread to spin if a sync-qualified or
future-qualified variable is not in the appropriate state for a given memory access,
until the thread gains access to the shared data. Spinning is the act of checking the
full-empty state repeatedly until the full-empty state changes to the state that the
memory operation needs to perform its operation.
This is necessary when synchronization operations are performed between multiple
separate processes. Threads that are blocked can only be unblocked by threads within
the same process because blocking and unblocking requires access to the runtime
internal data structures that are only accessible within the process to which the thread
belongs.
For more information, see the mmap(2) man page.
48 S247920