Static statement for atomic read / write value

Is there any way to check if reading / writing (loading / saving) values ​​is atomic? I have specialized versions of parallel containers that can only work with such values, and I would like to add a static statement to prevent accidental abuse.

This is true for all major x86_64 types, but this may not be true for all platforms or all long data types. In addition, it is possible that small structures and associations will also be assigned using the atomic operation (since they will simply be compiled to use the same size copy operation).

+4
source share
2 answers

The C ++ 0x project has a section with macros in the <atomic> header, which indicates that there is no easy and portable way to check this otherwise.

29.4 Property without locking [atomics.lockfree]

#define ATOMIC_CHAR_LOCK_FREE implementation-defined #define ATOMIC_CHAR16_T_LOCK_FREE implementation-defined #define ATOMIC_CHAR32_T_LOCK_FREE implementation-defined #define ATOMIC_WCHAR_T_LOCK_FREE implementation-defined #define ATOMIC_SHORT_LOCK_FREE implementation-defined #define ATOMIC_INT_LOCK_FREE implementation-defined #define ATOMIC_LONG_LOCK_FREE implementation-defined #define ATOMIC_LLONG_LOCK_FREE implementation-defined 

Macros indicate types where std :: atomic <type> can be implemented without blocking, which means that they themselves are atoms.

+2
source

The only method you have is to dump the generated assembly of each function and refer to the notes of the processor manufacturer to guarantee atomic instructions.

0
source

Source: https://habr.com/ru/post/1346535/


All Articles