i'm in a situation where i need to get boost::thread::id into a variable, but this variable is NOT a string, neither a string operation is allowed. is that possible?
maybe something like
char *tid = (casting something) boost::this_thread::get_id()
this is c++ on unix system. the reason why avoiding using string operation is because it slows down the whole application speed. thanks before.
In any event, your question seems to be entirely based on a misconception. If you want to get the boost::thread::id into a variable, the variable should be of type boost::thread::id. Like this:
boost::thread::id MyVariable = boost::thread::get_id();
No strings are involved at all. Why are you trying to cast it to a char *?
If your threads need to get their IDs so often that it's creating a bottleneck, you are likely doing something horribly wrong. Why do you need a thread's ID so much?
Update: Okay, so you need a thread ID that has specific semantics. You need to assign threads IDs that have the semantics you require. (There is no guarantee that whatever ID the threads already have is usable in a file name.) In pseudo-code:
Alternatively, your platform may have a function that provides the semantics you need. For example, Linux has gettid and NT has GetCurrentThreadId.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With