On 20.03.2018 09:24, Chris M. Thomasson wrote:
> I have always used my custom asm for this, but I noticed a while ago
> that C++11 can use Double-Width Compare-and-Swap (DWCAS) via a struct
> the size of two pointers for atomic operations. Out of interest, I have
> constructed the following program that works on MSVC 14.0.25424.00
> Update 3. However, on GCC 6.3.0, I am getting the following errors:
> ____________________________
> ||=== Build: Debug in ct_experiment (compiler: GNU GCC Compiler) ===|
> obj\Debug\main.o||In function `std::atomic<ct_dwcas>::is_lock_free()
> const':|
> C:\msys64\mingw64\include\c++\6.3.0\atomic|212|undefined reference to
> `__atomic_is_lock_free'|
> obj\Debug\main.o||In function
> `std::atomic<ct_dwcas>::load(std::memory_order) const':|
> C:\msys64\mingw64\include\c++\6.3.0\atomic|235|undefined reference to
> `__atomic_load_16'|
> obj\Debug\main.o||In function
> `std::atomic<ct_dwcas>::compare_exchange_weak(ct_dwcas&, ct_dwcas,
> std::memory_order, std::memory_order)':|
> C:\msys64\mingw64\include\c++\6.3.0\atomic|268|undefined reference to
> `__atomic_compare_exchange_16'|
> ||error: ld returned 1 exit status|
> ||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 0 second(s))
> ===|
>
[snip]
>
> I must be missing something in the ct_dwcas struct. Humm...
>
> Any thoughts? Help? Thanks. :^)
You probably need to link with some support library.
Until g++ 8.0 it was that way for e.g. filesystem sub-library.
Maybe it's still that way, IDK, I'm still on 7.2.
Cheers!,
- Alf