NUMA++ 0.12.0
Loading...
Searching...
No Matches
makeThreadExample3.cpp
Go to the documentation of this file.
1/**
2 * @file
3 * @copyright
4 * SPDX-FileCopyrightText: 2026-2026 European Southern Observatory (ESO)
5 *
6 * SPDX-License-Identifier: LGPL-3.0-only
7 */
8#include <chrono>
9#include <iostream>
10#include <numapp/numa.hpp>
11#include <numapp/thread.hpp>
12
13struct Example {
14 Example(std::chrono::milliseconds duration) : m_duration(duration) {
15 }
16 Example(Example&&) = default;
17
18 void ThreadFunc() {
19 std::cout << "Thread affinity: "
21
22 std::this_thread::sleep_for(m_duration);
23 }
24 std::chrono::milliseconds m_duration;
25};
26
27int main() {
28 using namespace numapp;
29 using namespace std::chrono_literals;
30 if (!NumaAvailable()) {
31 std::cout << "NUMA not available";
32 return -1;
33 }
34
35 NumaPolicies policies;
37 auto thread =
38 MakeJthread("myThread", policies, &Example::ThreadFunc, Example{500ms});
39}
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:35
Contains declarations for numapp thread utilities.