jonderry
jonderry

Reputation: 23633

In a multithreaded c++ program using boost, is there any way to get a pointer to the current thread?

I need to know the identity of the current thread to keep track of which threads are making certain requests to a shared data structure.

Upvotes: 1

Views: 120

Answers (2)

GManNickG
GManNickG

Reputation: 503755

You can use boost::this_thread::get_id() to get a boost::thread::id representing the thread.

I don't think you can get a pointer to a boost::thread object, because the thread doesn't necessarily have one attached. And it cannot make one because it might have one attached.

Upvotes: 6

Dewfy
Dewfy

Reputation: 23614

No way, but you can support hashmap of pairs: thread-id thread.

Upvotes: 0

Related Questions