<aside> 🖼️
자원 최대사용
리눅스 Linux (pthread + std::thread)
윈도우 Windows (SetThreadAffinityMask)
#include <thread>
#include <windows.h>
void worker() {
// 업무 코드
}
int main() {
std::thread t(worker);
// 스레드의 native handle 얻기
HANDLE hThread = (HANDLE)t.native_handle();
// 코어 2번만 사용 (비트마스크, 0x4 == 2번 코어)
SetThreadAffinityMask(hThread, 0x4);
// 워커풀 만들 때,
// os.cpu_count() - 1 만큼만 워커 생성
// 혹은, affinity를 코어 n-1개만으로 제한
t.join();
return 0;
}
</aside>