SHMEM\_TEST\_LOCK(3) Open MPI SHMEM\_TEST\_LOCK(3)

shmem\_set\_lock &lt;#shmem-set-lock&gt;(3), shmem\_clear\_lock &lt;#shmem-clear-lock&gt;(3), [shmem\_test\_lock(3)](/man/enterprise-packages/openmpi-cuda-12.9/shmem_test_lock.3) - Releases, locks, and tests a mutual exclusion memory lock.

# [SYNOPSIS](#SYNOPSIS)

C or C++:

```
#include <mpp/shmem.h>
void shmem_clear_lock(volatile long *lock)
void shmem_set_lock(volatile long *lock)
int shmem_test_lock(volatile long *lock)
```

Fortran:

```
INCLUDE "mpp/shmem.fh"
INTEGER lock, SHMEM_TEST_LOCK
CALL SHMEM_CLEAR_LOCK(lock)
CALL SHMEM_SET_LOCK(lock)
I = SHMEM_TEST_LOCK(lock)
```

# [DESCRIPTION](#DESCRIPTION)

The shmem\_set\_lock &lt;#shmem-set-lock&gt; routine sets a mutual exclusion lock after waiting for the lock to be freed by any other PE currently holding the lock. Waiting PEs are assured of getting the lock in a first-come, first-served manner.

The shmem\_clear\_lock &lt;#shmem-clear-lock&gt; routine releases a lock previously set by shmem\_set\_lock &lt;#shmem-set-lock&gt; after ensuring that all local and remote stores initiated in the critical region are complete.

The shmem\_test\_lock function sets a mutual exclusion lock only if it is currently cleared. By using this function, a PE can avoid blocking on a set lock. If the lock is currently set, the function returns without waiting. These routines are appropriate for protecting a critical region from simultaneous update by multiple PEs. They accept the following arguments:

[**lock**](#lock)

A symmetric data object that is a scalar variable or an array of length 1. This data object must be set to 0 on all processing elements (PEs) prior to the first use. lock must be of type integer. If you are using Fortran, it must be of default kind.

# [NOTES](#NOTES)

The term symmetric data object is defined on [*intro\_shmem*(3)](/man/enterprise-packages/openmpi-cuda-12.9/intro_shmem.3).

# [RETURN VALUES](#RETURN_VALUES)

The shmem\_test\_lock function returns 0 if the lock was originally cleared and this call was able to set the lock. A value of 1 is returned if the lock had been set and the call returned without waiting to set the lock.

**See also:**

[*intro\_shmem*(3)](/man/enterprise-packages/openmpi-cuda-12.9/intro_shmem.3)

# [Copyright](#Copyright)

2003-2026, The Open MPI Community

November 1, 2026

---

Document: shmem_test_lock(3) from openmpi-cuda-12.9 5.0.11-r1 (Chainguard OS)
Source: https://github.com/open-mpi/ompi
