너무 늦었지만는 대답을 찾고있는 사용자를 위해, 부스트는 스레드 ID를 참조 할 수 있습니다 원하는 숫자가 아닙니다. 그러나이 숫자를 예를 들어 unsigned long으로 쉽게 변환 할 수 있습니다. id는 16 진수 표현으로되어 있습니다. 이 작은 기능은 드 작업을 수행합니다
4491075584
4491612160
4492148736
4492685312
4493221888
4493758464
4494295040
4494831616
4495368192
4495904768
이 boost_thread와 boost_system와 링크를 잊지 마세요 :
#include <boost/lexical_cast.hpp>
#include <boost/thread.hpp>
unsigned long getThreadId(){
std::string threadId = boost::lexical_cast<std::string>(boost::this_thread::get_id());
unsigned long threadNumber = 0;
sscanf(threadId.c_str(), "%lx", &threadNumber);
return threadNumber;
}
void drawThreadId(){
std::cout << getThreadId() << std::endl;
boost::this_thread::sleep(boost::posix_time::milliseconds(500));
}
int main() {
for(int i=0; i<10; i++){
boost::thread thread = boost::thread(drawThreadId);
}
return 0;
}
이 이런 식으로 뭔가를 반환합니다.
희망이 도움이됩니다.
그래서 함수에 매개 변수로 출력 스트림 연산자와 함께 사용되는 boost :: thread :: id를 전달하겠습니까? 스트림이나 스트림 연산자없이 값을 사용할 수있게하려면 무엇을 제외하고는 거의 소리가 나지 않습니까? – AJG85
boost :: this_thread :: get_id()를 스레드 작업자 함수 내에서 사용하면 실제로 sprintf_s 스타일을 사용하여 매개 변수를 지정하지 않아도됩니다. – AJG85