[CC += gcc-help@] Hi Rahl, On Fri, Feb 28, 2025 at 10:13:04AM +0000, rahl wrote: > I noticed that 'const' is used for both 'one' and 'zero' variables in > the Examples section demo code of manpage 'futex(2)'. > > The variables are both used in calls to > 'atomic_compare_exchange_strong()' where the 'const' is discarded as > it may write to the 'expected' parameter during a "failure" case. I don't understand what that function is. It doesn't have a manual page, and it's neither in /usr/include. It doesn't appear in the GCC manual either. And it's not described in ISO C. What is that function? I'd like to understand what we're calling to be able to understand how the calling code is wrong. BTW, there seem to be other important bugs in that example program, which I don't understand either. Would you mind having a look at those (I'm assuming that you seem familiar with these atomic APIs)? See: $ man futex 2>/dev/null \ | sed -n '/^EXAMPLES/,/^[^ ]/p' \ | sed -n '/^ *Program source$/,$p' \ | head -n-1 \ | tail -n+2 \ | clang -x c -; <stdin>:58:20: error: address argument to atomic operation must be a pointer to _Atomic type ('uint32_t *' (aka 'unsigned int *') invalid) 58 | if (atomic_compare_exchange_strong(futexp, &one, 0)) | ^ ~~~~~~ /usr/lib/llvm-19/lib/clang/19/include/stdatomic.h:150:67: note: expanded from macro 'atomic_compare_exchange_strong' 150 | #define atomic_compare_exchange_strong(object, expected, desired) __c11_atomic_compare_exchange_strong(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) | ^ ~~~~~~ <stdin>:82:16: error: address argument to atomic operation must be a pointer to _Atomic type ('uint32_t *' (aka 'unsigned int *') invalid) 82 | if (atomic_compare_exchange_strong(futexp, &zero, 1)) { | ^ ~~~~~~ /usr/lib/llvm-19/lib/clang/19/include/stdatomic.h:150:67: note: expanded from macro 'atomic_compare_exchange_strong' 150 | #define atomic_compare_exchange_strong(object, expected, desired) __c11_atomic_compare_exchange_strong(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) | ^ ~~~~~~ 2 errors generated. > Attached is the trivial patch to remove the offending qualifiers. Please provide a complete patch, with a commit message. See the files under <CONTRIBUTING.d/>. Have a lovely night! Alex -- <https://www.alejandro-colomar.es/>
Attachment:
signature.asc
Description: PGP signature