Project Home
Project Home
Source Code
Source Code
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - API for unique thread-id in QNX: (4 Items)
   
API for unique thread-id in QNX  
Is there any API to obtain *unique* thread-id at least at the process level (if not across processes) in the QNX? Like 
Linux and Android support gettid API/syscall which returns unique thread-id. Any help is highly appreciated.

Please note Id obtained by pthread_self() may be reused after a terminated thread has been joined, or a detached thread 
has terminated.
RE: API for unique thread-id in QNX  
You could use a pthread key and store the value of a global counter which you could use as a unique id?
RE: API for unique thread-id in QNX  
If this is related to the MIB3 logging requirements the closest we have is maybe to use.
 
volatile struct _thread_local_storage	*tls = LIBC_TLS();
tls->__owner

which will give you a system wide unique id, but only for that instance, if processes or thread ends it can be reused. 
But then again you have the same issue for gettid.
So if you want runtime unique you'll need a custom solution for both linux and qnx, with a value larger than 32bit.


-----Original Message-----
From: Mayank Jain [mailto:community-noreply@qnx.com] 
Sent: Montag, 1. Juni 2015 14:14
To: general-toolchain
Subject: API for unique thread-id in QNX

Is there any API to obtain *unique* thread-id at least at the process level (if not across processes) in the QNX? Like 
Linux and Android support gettid API/syscall which returns unique thread-id. Any help is highly appreciated.

Please note Id obtained by pthread_self() may be reused after a terminated thread has been joined, or a detached thread 
has terminated.



_______________________________________________

General
http://community.qnx.com/sf/go/post113881
To cancel your subscription to this discussion, please e-mail general-toolchain-unsubscribe@community.qnx.com
Re: RE: API for unique thread-id in QNX  
I tried below code as a cross-platform solution to obtain unique id and it appears to work on Linux, Mac and Windows 
(maybe I'm lucky). On the other hand thread-ids are being reused after thread termination (join) in the same process on 
QNX.

uint32_t MyGetTid (void)
{
    uint32_t tid = ~0U;

#if defined(__linux__)
    tid = syscall(SYS_gettid);
#elif defined(__APPLE__)
    // Mac OS >= 10.6 has a system call equivalent to Linux's gettid()
    tid = syscall(SYS_thread_selfid);
#elif defined _WIN32
    tid = GetCurrentThreadId();
#elif defined(__ANDROID__)
    tid = gettid();
#elif defined(__QNX__)
    // FIXME: gettid() appears to reuse the thread-id on QNX
    tid = gettid();
#endif
    return tid;
}