NUMA++ 0.11.0
Loading...
Searching...
No Matches
makeThreadExample3.cpp
1#include <chrono>
2#include <iostream>
3#include <numapp/numa.hpp>
4#include <numapp/thread.hpp>
5
6struct Example {
7 Example(std::chrono::milliseconds duration) : m_duration(duration) {
8 }
9 Example(Example&&) = default;
10
11 void ThreadFunc() {
12 std::cout << "Thread affinity: "
14
15 std::this_thread::sleep_for(m_duration);
16 }
17 std::chrono::milliseconds m_duration;
18};
19
20int main() {
21 using namespace numapp;
22 using namespace std::chrono_literals;
23 if (!NumaAvailable()) {
24 std::cout << "NUMA not available";
25 return -1;
26 }
27
28 NumaPolicies policies;
30 auto thread =
31 MakeJthread("myThread", policies, &Example::ThreadFunc, Example{500ms});
32}
static CpuAffinity MakeFromCpuStringAll(char const *cpustring)
Create CpuAffinity from `cpustring` without considering current cpuset.
static CpuAffinity MakeFromActive()
Create current affinity settings.
Combines the the available NUMA policy types in one object.
void SetCpuAffinity(std::optional< CpuAffinity > affinity) noexcept
Set CPU affinity.
bool NumaAvailable() noexcept
Query whether system has NUMA support.
Definition numa.hpp:34
Contains declarations for numapp thread utilities.