NUMA++ 0.12.0
Loading...
Searching...
No Matches
makeThreadExample.cpp
Go to the documentation of this file.
1/**
2 * @file
3 * @copyright
4 * SPDX-FileCopyrightText: 2023-2023 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
13void ThreadFunc(std::chrono::milliseconds duration) {
14 std::cout << "Thread affinity: " << numapp::CpuAffinity::MakeFromActive() << std::endl;
15
16 std::this_thread::sleep_for(duration);
17}
18
19int main() {
20 using namespace numapp;
21 using namespace std::chrono_literals;
22 if (!NumaAvailable()) {
23 std::cout << "NUMA not available";
24 return -1;
25 }
26
27 NumaPolicies policies;
29 auto thread = MakeThread("myThread", policies, &ThreadFunc, 500ms);
30
31 thread.join();
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:35
std::thread MakeThread(std::string_view thread_name, NumaPolicies const &policies, Func &&func, Args &&... args)
Primary overload accepting string-view for thread_name.
Definition thread.hpp:146
Contains declarations for numapp thread utilities.