std::hardware_destructive_interference_size, std::hardware_constructive_interference_size - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::hardware_destructive_interference_size, std::hardware_constructive_interference_size

From cppreference.com
< cpp‎ | thread

Defined in header `<new>` |  |
inline constexpr std::size_t hardware_destructive_interference_size = /*implementation-defined*/; | (1) | (since C++17)
inline constexpr std::size_t hardware_constructive_interference_size = /*implementation-defined*/; | (2) | (since C++17)

1) Minimum offset between two objects to avoid false sharing. Guaranteed to be at least alignof(std::max_align_t)

    struct keep_apart {
      alignas(std::hardware_destructive_interference_size) std::atomic<int> cat;
      alignas(std::hardware_destructive_interference_size) std::atomic<int> dog;
    };

2) Maximum size of contiguous memory to promote true sharing. Guaranteed to be at least alignof(std::max_align_t)

    struct together {
      atomic<int> dog;
      int puppy;
    };
    struct kennel {
      // Other data members...
      alignas(sizeof(together)) together pack;
      // Other data members...
    };
    static_assert(sizeof(together) <= std::hardware_constructive_interference_size);

### [edit] Notes

These constants provide a portable way to access the L1 data cache line size.

### [edit] Example

| This section is incomplete Reason: no example

### [edit] See also

hardware_concurrency [static] | returns the number of concurrent threads supported by the implementation (public static member function of `std::thread`) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/thread/hardware_destructive_interference_size&oldid=90721"
Category:

- Todo no example