I am porting an application that currently runs on HP-UX and AIX to
Linux.
HP-UX and AIX both have pthread functions to get a unique sequence
number identifying a particular thread.
For HP, it is pthread_getsequence_np(...)
For AIX, it is pthread_getunique_np(...)
I have noticed that neither of these methods exist on my Linux
distribution.
Is there a Linux equivalent to the aforementioned methods?
I did a quick flyby in pthread.h, but didn't notice anything that
could help me.
Many thanks,
AJ
comp.programming.threads
> For HP, it is pthread_getsequence_np(...)
> For AIX, it is pthread_getunique_np(...)
>
> Is there a Linux equivalent to the aforementioned methods?
I don't believe there is such a function on Linux, nor is one
usually necessary, since the same result is trivial to achieve in a
completely portable way: just count how many threads you've created
so far, and pass the sequence number to your 'thread routine',
which can then store it in a thread-specific variable.
If you are writing a library, and do not have control over thread
creation, you can still get the answer pretty easily:
// warning: untested code ...
size_t get_sequence()
{
static size_t seq;
__thread size_t my_seq;
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
if (!my_seq) {
// haven't see this thread yet
pthread_mutex_lock(&mtx);
my_seq = ++seq;
pthread_mutex_unlock(&mtx);
}
return my_seq;
}
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Thanks for the insight, Paul. I greatly appreciate it.