Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #81335

Re: DCAS-supplement ?

From "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Newsgroups comp.lang.c++
Subject Re: DCAS-supplement ?
Date 2021-09-19 15:29 -0700
Organization Aioe.org NNTP Server
Message-ID <si8dkm$6cv$1@gioia.aioe.org> (permalink)
References <si7njq$udv$1@dont-email.me>

Show all headers | View raw


On 9/19/2021 9:13 AM, Bonita Montero wrote:
> I just wanted to test if my compiler recognizes ...
>      atomic<pair<uintptr_t, uintptr_t>
> ... and uses DCASes on it or if it supplements the pair with a usual
> lock. 

[...]

Can you get this to compile on your MSVC?
_________________________
#include <iostream>
#include <atomic>
#include <xmmintrin.h>

int main()
{
     std::atomic<__int64> foo_64;
     std::atomic<__m128> foo_128;

     std::cout << sizeof(__int64) << "\n";
     std::cout << sizeof(__m128) << "\n";

     std::cout << foo_64.is_lock_free() << "\n";
     std::cout << foo_128.is_lock_free() << "\n";

     return 0;
}
_________________________


In 64-bit mode I am getting:

8
16
1
0

This means that this compiler is not supporting lock-free operations on 
128-bit numbers in 64-bit mode, humm. What do you get? Also, you might 
try to see if your system supports the CMPXCHG16B instruction. If so, 
code DWCAS manually in assembly language. Now, in 32 bit mode, I also get:

8
16
1
0

This means that DWCAS _is_ supported in a lock-free manner in 32 bit 
mode through CMPXCHG8B. So, try to use CMPXCHG16B directly if you want 
DWCAS in 64-bit mode.

I have not tried this experiment in GCC. It might work with __int128, 
and end up using:

https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html

__atomic_compare_exchange_16, you might have to use -mcx16.

Hope that helps a bit!

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

DCAS-supplement ? Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-19 18:13 +0200
  Re: DCAS-supplement ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-19 15:29 -0700
    Re: DCAS-supplement ? Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-20 07:03 +0200
      Re: DCAS-supplement ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-19 22:19 -0700
        Re: DCAS-supplement ? Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-20 07:26 +0200
          Re: DCAS-supplement ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-19 22:40 -0700
          Re: DCAS-supplement ? Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-20 07:53 +0200
            Re: DCAS-supplement ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-20 16:02 -0700
              Re: DCAS-supplement ? Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-21 09:31 +0200
                Re: DCAS-supplement ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-21 16:09 -0700

csiph-web