I’m working with boost threads and I need to reference a thread from its thread function so I can store it in a map with its corresponding thread id. The main idea is that I will be using another thread to gather thread stats by querying the proc table, so I cant use boost::this_thread::get_id(). I need to store the thread so I can call interrupts and joins on specific threads.
The following insert statement doesn’t work, but I would have expected this or &this to reference the thread.
Thread function:
workerFunc(){
std::string tid;
tid=boost::lexical_cast<string>(syscall(SYS_gettid));
threadMap.insert(pair<std::string,boost::thread>(tid,this));
}
Currently I have the parent make the insert but wait for the thread to get its thread id, but that is not what a want.
How can I store the thread/a pointer to the thread without using the parent?
By using a functor instead of a function, you can add state to it.