c++11 has a possibility of getting current thread id, but it is not castable to integer type:
cout<<std::this_thread::get_id()<<endl;
output : 139918771783456
cout<<(uint64_t)std::this_thread::get_id()<<endl;
error: invalid cast from type ‘std::thread::id’ to type ‘uint64_t’ same for other types: invalid cast from type ‘std::thread::id’ to type ‘uint32_t’
I really dont want to do pointer casting to get the integer thread id. Is there some reasonable way(standard because I want it to be portable) to do it?
operator<<
seems to handle fine). – hmakholm left over Monica Sep 15 '11 at 14:07thread::id
isn't represented as an integer at all. The page you link to uses an array, indexed by thread ID. Have you considered using amap<thread::id, int>
instead? Then you can use the relational operators already defined for theid
class without doing any conversions. The standard also defineshash<thread::id>
, so you can use the unordered containers, too. – Rob Kennedy Sep 15 '11 at 15:07