##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# atomic_is_lock_free

From cppreference.com
< c‎ | atomic

Defined in header `<stdatomic.h>` |  |
_Bool atomic_is_lock_free( const volatile A* obj ); |  | (since C11)

Determines if the atomic operations on all objects of the type `A` (the type of the object pointed to by `obj`) are lock-free. In any given program execution, the result of calling `atomic_is_lock_free` is the same for all pointers of the same type.

This is a generic function defined for all atomic object types `A`. The argument is pointer to a volatile atomic type to accept addresses of both non-volatile and volatile (e.g. memory-mapped I/O) atomic variables.

### [edit] Parameters

obj | - | pointer to the atomic object to inspect

### [edit] Return value

true if the the operations on all objects of the type `A` are lock-free, `false` otherwise.

### [edit] Notes

C11, as published, specified that this function is per-object, not per-type. This was corrected by DR 465.

### [edit] Example

Run this code

    #include <stdio.h>
    #include <stdatomic.h>

    _Atomic struct A { int a[100]; } a;
    _Atomic struct B { int x, y; } b;
    int main(void)
    {
        printf("_Atomic struct A is lock free? %s\n",
                atomic_is_lock_free(&a) ? "true" : "false");
        printf("_Atomic struct B is lock free? %s\n",
                atomic_is_lock_free(&b) ? "true" : "false");
    }

Possible output:

    _Atomic struct A is lock free? false
    _Atomic struct B is lock free? true

### [edit] References

- C11 standard (ISO/IEC 9899:2011):

  - 7.17.5.1 The atomic_is_lock_free generic function (p: 280)

### [edit] See also

ATOMIC_BOOL_LOCK_FREE ATOMIC_CHAR_LOCK_FREE ATOMIC_CHAR16_T_LOCK_FREE ATOMIC_CHAR32_T_LOCK_FREE ATOMIC_WCHAR_T_LOCK_FREE ATOMIC_SHORT_LOCK_FREE ATOMIC_INT_LOCK_FREE ATOMIC_LONG_LOCK_FREE ATOMIC_LLONG_LOCK_FREE ATOMIC_POINTER_LOCK_FREE (C11) | indicates that the given atomic type is lock-free (macro constant) [edit]
C++ documentation for atomic_is_lock_free

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/atomic/atomic_is_lock_free&oldid=86848"