std::jthread:: get_id
From cppreference.net
C++
Concurrency support library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::jthread
| Member functions | ||||
| Observers | ||||
|
jthread::get_id
|
||||
| Operations | ||||
| Stop token handling | ||||
| Non-member functions | ||||
|
std
::
jthread
::
id
get_id
(
)
const
noexcept
;
|
(C++20 이후) | |
std::jthread::id 값(이는 std::thread::id 의 타입 별칭임)을 반환하며, 이는 * this 와 연결된 스레드를 식별합니다.
목차 |
매개변수
(없음)
반환값
std::jthread::id 타입의 값으로, * this 와 연관된 스레드를 식별합니다. 연관된 스레드가 없는 경우, 기본 생성된 std::jthread::id 가 반환됩니다.
예제
이 코드 실행
#include <chrono> #include <iostream> #include <thread> void foo() { std::this_thread::sleep_for(std::chrono::seconds(1)); } int main() { std::jthread t1(foo); std::jthread::id t1_id = t1.get_id(); std::jthread t2(foo); std::jthread::id t2_id = t2.get_id(); std::cout << "t1's id: " << t1_id << '\n'; std::cout << "t2's id: " << t2_id << '\n'; t1.join(); t2.join(); std::cout << "t1's id after join: " << t1.get_id() << '\n'; std::cout << "t2's id after join: " << t2.get_id() << '\n'; }
가능한 출력:
t1's id: 140146221688576 t2's id: 140146213295872 t1's id after join: thread::id of a non-executing thread t2's id after join: thread::id of a non-executing thread
참고 항목
|
스레드의
id
를 나타냄
(
std::thread
의 public member class)
|
|
|
스레드가 조인 가능한지 확인함, 즉 병렬 컨텍스트에서 실행 중일 수 있는지 여부
(public member function) |