blob: 373ff24223323dea4d691407e033bfdfbd7e8a2b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
<h1 id="firstHeading" class="firstHeading">atomic_is_lock_free</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><stdatomic.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c11"> <td> <pre data-language="c">_Bool atomic_is_lock_free( const volatile A* obj );</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c11">(since C11)</span> </td> </tr> </table> <p>Determines if the atomic operations on all objects of the type <code>A</code> (the type of the object pointed to by <code>obj</code>) are lock-free. In any given program execution, the result of calling <code>atomic_is_lock_free</code> is the same for all pointers of the same type.</p>
<p>This is a <a href="../language/generic" title="c/language/generic">generic function</a> defined for all <a href="../language/atomic" title="c/language/atomic">atomic object types</a> <code>A</code>. The argument is pointer to a volatile atomic type to accept addresses of both non-volatile and <a href="../language/volatile" title="c/language/volatile">volatile</a> (e.g. memory-mapped I/O) atomic objects, and volatile semantic is preserved when applying this operation to volatile atomic objects.</p>
<p>It is unspecified whether the name of a generic function is a macro or an identifier declared with external linkage. If a macro definition is suppressed in order to access an actual function (e.g. parenthesized like <code>(atomic_is_lock_free)(...)</code>), or a program defines an external identifier with the name of a generic function, the behavior is undefined.</p>
<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> obj </td> <td> - </td> <td> pointer to the atomic object to inspect </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> <p><code>true</code> if the operations on all objects of the type <code>A</code> are lock-free, <code>false</code> otherwise.</p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#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");
}</pre></div> <p>Possible output:</p>
<div class="text source-text"><pre data-language="c">_Atomic struct A is lock free? false
_Atomic struct B is lock free? true</pre></div> </div> <h3 id="Defect_reports"> Defect reports</h3> <p>The following behavior-changing defect reports were applied retroactively to previously published C standards.</p>
<table class="dsctable"> <tr> <th>DR </th> <th>Applied to </th> <th>Behavior as published </th> <th>Correct behavior </th>
</tr> <tr> <td>
<a rel="nofollow" class="external text" href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2396.htm#dr_465">DR 465</a> </td> <td>C11 </td> <td>this function was per-object </td> <td>this functions is per-type </td>
</tr>
</table> <h3 id="References"> References</h3> <ul>
<li> C17 standard (ISO/IEC 9899:2018): </li>
<ul><li> 7.17.5.1 The atomic_is_lock_free generic function (p: 205) </li></ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.17.5.1 The atomic_is_lock_free generic function (p: 280) </li></ul>
</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="atomic_lock_free_consts" title="c/atomic/ATOMIC LOCK FREE consts"> <span class="t-lines"><span>ATOMIC_BOOL_LOCK_FREE</span><span>ATOMIC_CHAR_LOCK_FREE</span><span>ATOMIC_CHAR16_T_LOCK_FREE</span><span>ATOMIC_CHAR32_T_LOCK_FREE</span><span>ATOMIC_WCHAR_T_LOCK_FREE</span><span>ATOMIC_SHORT_LOCK_FREE</span><span>ATOMIC_INT_LOCK_FREE</span><span>ATOMIC_LONG_LOCK_FREE</span><span>ATOMIC_LLONG_LOCK_FREE</span><span>ATOMIC_POINTER_LOCK_FREE</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> indicates that the given atomic type is lock-free <br> <span class="t-mark">(macro constant)</span> </td>
</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/atomic/atomic_is_lock_free" title="cpp/atomic/atomic is lock free">C++ documentation</a></span> for <code>atomic_is_lock_free</code> </td>
</tr> </table> <div class="_attribution">
<p class="_attribution-p">
© cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
<a href="https://en.cppreference.com/w/c/atomic/atomic_is_lock_free" class="_attribution-link">https://en.cppreference.com/w/c/atomic/atomic_is_lock_free</a>
</p>
</div>
|