简体   繁体   中英

Atomic array in C11

Based on the reference , the _Atomic type specifier can not be used on arrays. Is there a standard way/workaround to be able to issue atomic_exchange calls for an object that is stored within the array?

The standard prohibits to apply the _Atomic specifier to an array as a whole, for example this

typedef double at[5];
_Atomic(at) atomic_array; // constraint violation

But the array elements may well be atomic

_Atomic(double) atomic_array[5]; // valid

If you want the access to the array as a whole to be atomic, you'd have to encapsulate the array within a structure and then have the _Atomic around the structure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM