std::jthread:: native_handle
From cppreference.net
C++
Concurrency support library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::jthread
| Member functions | ||||
| Observers | ||||
|
jthread::native_handle
|
||||
| Operations | ||||
| Stop token handling | ||||
| Non-member functions | ||||
|
native_handle_type native_handle
(
)
;
|
(C++20부터)
(항상 존재하지는 않음) |
|
구현에서 정의된 기본 스레드 핸들을 반환합니다.
목차 |
매개변수
(없음)
반환값
스레드를 나타내는 구현 정의 핸들 유형입니다.
예외
구현 정의 예외를 던질 수 있습니다.
예제
native_handle
을 사용하여 POSIX 시스템에서 C++ 스레드의 실시간 스케줄링을 활성화합니다.
이 코드 실행
#include <chrono> #include <cstring> #include <iostream> #include <mutex> #include <pthread.h> #include <thread> std::mutex iomutex; void f(int num) { std::this_thread::sleep_for(std::chrono::seconds(1)); sched_param sch; int policy; pthread_getschedparam(pthread_self(), &policy, &sch); std::lock_guard<std::mutex> lk(iomutex); std::cout << "Thread " << num << " is executing at priority " << sch.sched_priority << '\n'; } int main() { std::jthread t1(f, 1), t2(f, 2); sched_param sch; int policy; pthread_getschedparam(t1.native_handle(), &policy, &sch); sch.sched_priority = 20; if (pthread_setschedparam(t1.native_handle(), SCHED_FIFO, &sch)) std::cout << "Failed to setschedparam: " << std::strerror(errno) << '\n'; }
출력:
Thread 2 is executing at priority 0 Thread 1 is executing at priority 20