728x90
#include <thread>
#include <iostream>
using namespace std;
void HelloWorld()
{
cout << "Hello World" << endl;
}
int main()
{
thread t(HelloWorld);
int32 count = t.hardware_concurrency(); // CPU 코어 개수 출력
thread::id id = t.get_id(); // 쓰레드마다 부여된 아이디 출력 ( 순차적으로 증가하는건 아니지만 겹치진 않음 )
// t.detach(); // 쓰레드 객체에서 실제 쓰레드를 분리 ( 백그라운드 쓰레드로 변경 ) ( 리눅스의 데몬 쓰레드 )
if (t.joinable()) // join할 수 있는 상태인지 체크 ( id를 부여받아서 0이 아닌지 체크 )
t.join(); // 메인쓰레드가 아닌 쓰레드가 일을 다 할때까지 대기
}
728x90