docs/classtf_1_1CachelineAligned.html
| | Taskflow: A General-purpose Task-parallel Programming System |
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
tf::CachelineAligned< T > Class Template Reference
class to ensure cacheline-aligned storage for an object. More...
#include <taskflow/utility/os.hpp>
|
|
| T & | get () |
| | accesses the underlying object
|
| |
| const T & | get () const |
| | accesses the underlying object as a constant reference
|
| |
|
|
| T | data |
| | The stored object, aligned to twice the cacheline size.
|
| |
template<typename T>
class tf::CachelineAligned< T >
class to ensure cacheline-aligned storage for an object.
Template Parameters
| T | The type of the stored object. |
This utility class aligns the stored object data to twice the size of a cacheline. The alignment improves performance by optimizing data access in cache-sensitive scenarios.
// create two integers on two separate cachelines to avoid false sharing
tf::CachelineAligned<int> counter1;
tf::CachelineAligned<int> counter2;
// two threads access the two counters without false sharing
std::thread t1([&]{ counter1.get() = 1; });
std::thread t2([&]{ counter2.get() = 2; });
t1.join();
t2.join();
class to ensure cacheline-aligned storage for an object.
Definition os.hpp:219
T & get()
accesses the underlying object
Definition os.hpp:239
template<typename T>
|
| T & tf::CachelineAligned< T >::get | ( | | ) | |
| inline |
accesses the underlying object
Returnsa reference to the underlying object.
Returns a mutable reference to the stored object so it can be read or written directly without copying.
tf::CachelineAligned<int> counter;
counter.get() = 1;
template<typename T>
|
| const T & tf::CachelineAligned< T >::get | ( | | ) | const |
| inline |
accesses the underlying object as a constant reference
Returnsa constant reference to the underlying object.
Returns a read-only reference to the stored object, for use on const-qualified instances of CachelineAligned.
const tf::CachelineAligned<int> counter;
int v = counter.get();
The documentation for this class was generated from the following file:
taskflow/utility/os.hpp
Maintained by Dr. Tsung-Wei Huang — Generated by 1.13.1