/ , , Johannes Schaub - litb , : . . , (, , ):
#include <windows.h>
#include <iostream>
#include "boost/thread.hpp"
using namespace std;
template<typename Tag, typename Tag::type M>
struct Rob {
friend typename Tag::type get(Tag) {
return M;
}
};
struct thread_data_f {
typedef unsigned boost::detail::thread_data_base::*type;
friend type get(thread_data_f);
};
struct thread_id_f {
typedef boost::detail::thread_data_ptr boost::thread::id::*type;
friend type get(thread_id_f);
};
template struct Rob<thread_data_f, &boost::detail::thread_data_base::id>;
template struct Rob<thread_id_f, &boost::thread::id::thread_data>;
unsigned int get_native_thread_id( boost::thread const& t)
{
boost::detail::thread_data_ptr thread_data = t.get_id().*get(thread_id_f());
unsigned thread_id = (*thread_data).*get(thread_data_f());
return thread_id;
}
void thread_func()
{
cout << "thread running..." << endl;
cout << "Windows says my ID is: " << GetCurrentThreadId() << endl;
for (;;) {
boost::this_thread::yield();
}
}
int main()
{
boost::thread t(thread_func);
::Sleep(2000);
cout << "boost says my thread ID is: " << get_native_thread_id(t) << endl;
return 0;
}
, " " . , - . :
- MinGW 4.6.1
-Wall -Wextra - . " " script. - V++ 2008 2010 /W 4
, , :
C:\temp>test
thread running...
Windows says my ID is: 5388
boost says my thread ID is: 5388
, , , / boost:: thread , , , .
/:
"", , ++ 03 14.7.2/8 " ":
, . [: , , ( , ) , , - -, .]
"", , , :
, : . !