ACE_OS::thr_self() returns ACE_thread_t. ACE logger has a switch "\t" to print it. How can I do it if I want to print thread id by using printf()?
+1
A:
If ACE doesn't provide a method to do it you have to figure out its type. Given that it is ACE, it is probably hidden behind 3 typedefs nested in 5 #defines. The header file OS_NS_Thread.h
looks like as good a starting point as any.
Duck
2009-11-16 16:08:54
If `ACE_thread_t` is like `pthread_t` it will boil down to either an integer ("%d" or "%x") or a pointer ("%p"). The rationale here is that these are (a) lightweight, and (b) unique. This may not be the case. It's possible `ACE_thread_t` will be a complex type. If it's public you may be able to get the id out of it. If it's not there will be need to be some API call for you to get the actual thread id. Be very careful with this though, because the type is likely different from platform to platform and there's no guarantee of portability.
quark
2009-11-16 16:36:21
A:
ACE? C++? Why not use iostream instead of printf?
ACE_thread_t id = ACE_OS::thr_self();
unsigned char content[sizeof(id)];
size_t i;
memcpy(content, &id, sizeof(id) );
for (i=0; i<sizeof(id); ++i) printf("%02X",content[i]);
OwnWaterloo
2009-12-03 00:37:07