Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/thread/hardware destructive interference size"

From cppreference.com
< cpp‎ | thread
m (+header, -another copypaste)
Line 20: Line 20:
 
};
 
};
 
}}
 
}}
@2@ Maximum size of contiguous memory to promote true sharing. Guaranteed to be at least {{c|alignof(max_align_t)}}
+
@2@ Maximum size of contiguous memory to promote true sharing. Guaranteed to be at least {{c|alignof(std::max_align_t)}}
 
{{source|1=
 
{{source|1=
 
struct together {
 
struct together {

Revision as of 03:31, 15 November 2016

 
 
Concurrency support library
Threads
(C++11)
(C++20)
hardware_destructive_interference_sizehardware_constructive_interference_size
(C++17)(C++17)
this_thread namespace
(C++11)
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
(C++11)
Generic lock management
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
Safe Reclamation
(C++26)
Hazard Pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11)(deprecated in C++20)
(C++11)(deprecated in C++20)
Memory ordering
Free functions for atomic operations
Free functions for atomic flags
 
Defined in header <new>
static constexpr std::size_t
    hardware_destructive_interference_size = /*implementation-defined*/;
(1) (since C++17)
static 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);

Notes

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

Example

See also

returns the number of concurrent threads supported by the implementation
(public static member function of std::{{{1}}}) [edit]