Difference between revisions of "cpp/atomic/atomic is lock free"
(fmt) |
(no per-object test here either, atomic_is_lock_free gives the same result for all objects of the given type [atomics.lockfree]/2) |
||
Line 26: | Line 26: | ||
{{dcl end}} | {{dcl end}} | ||
− | @1@ Determines if the atomic object pointed to by {{tt|obj}} is implemented lock-free, as if by calling {{c|obj->is_lock_free()}} | + | @1@ Determines if the atomic object pointed to by {{tt|obj}} is implemented lock-free, as if by calling {{c|obj->is_lock_free()}}. In any given program execution, the result of the lock-free query is the same for all pointers of the same type. |
− | @2@ Expands to an integer constant expression with value {{c|0}} for the built-in atomic types that are never lock-free | + | @2@ Expands to an integer constant expression with value |
+ | * {{c|0}} for the built-in atomic types that are never lock-free | ||
+ | * {{c|1}} for the built-in atomic types that are ''sometimes'' lock-free | ||
+ | * {{c|2}} for the built-in atomic types that are always lock-free. | ||
===Parameters=== | ===Parameters=== | ||
Line 42: | Line 45: | ||
===Notes=== | ===Notes=== | ||
− | All atomic types except for {{lc|std::atomic_flag}} may be implemented using mutexes or other locking operations, rather than using the lock-free atomic CPU instructions. Atomic types are also allowed to be ''sometimes'' lock-free, e.g. if only aligned memory accesses are naturally atomic on a given architecture, misaligned objects of the same type have to use locks | + | All atomic types except for {{lc|std::atomic_flag}} may be implemented using mutexes or other locking operations, rather than using the lock-free atomic CPU instructions. Atomic types are also allowed to be ''sometimes'' lock-free, e.g. if only aligned memory accesses are naturally atomic on a given architecture, misaligned objects of the same type have to use locks. |
===Example=== | ===Example=== |
Revision as of 10:26, 28 January 2015
Defined in header <atomic>
|
||
(1) | (since C++11) | |
template< class Atomic > bool atomic_is_lock_free( const volatile Atomic* obj ) |
||
template< class Atomic > bool atomic_is_lock_free( const Atomic* obj ) |
||
#define ATOMIC_CHAR_LOCK_FREE /* unspecified */ #define ATOMIC_CHAR16_T_LOCK_FREE /* unspecified */ |
(2) | (since C++11) |
obj
is implemented lock-free, as if by calling obj->is_lock_free(). In any given program execution, the result of the lock-free query is the same for all pointers of the same type.- 0 for the built-in atomic types that are never lock-free
- 1 for the built-in atomic types that are sometimes lock-free
- 2 for the built-in atomic types that are always lock-free.
Contents |
Parameters
obj | - | pointer to the atomic object to examine |
Return value
true if *obj is a lock-free atomic, false otherwise.
Exceptions
Notes
All atomic types except for std::atomic_flag may be implemented using mutexes or other locking operations, rather than using the lock-free atomic CPU instructions. Atomic types are also allowed to be sometimes lock-free, e.g. if only aligned memory accesses are naturally atomic on a given architecture, misaligned objects of the same type have to use locks.
Example
This section is incomplete Reason: no example |
See also
checks if the atomic object is lock-free (public member function of std::atomic<T> )
| |
specializes atomic operations for std::shared_ptr (function template) | |
(C++11) |
the lock-free boolean atomic type (class) |