Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Thread Sequence Number In Linux

2 views
Skip to first unread message

aj

unread,
Dec 6, 2007, 3:10:51 PM12/6/07
to
Sorry if this is slightly off-topic, I don't know where else to post
this.

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

shakah...@gmail.com

unread,
Dec 6, 2007, 4:19:15 PM12/6/07
to
On Dec 6, 3:10 pm, aj <a...@bookac.com> wrote:
> Sorry if this is slightly off-topic, I don't know where else to post
> this.

comp.programming.threads

Paul Pluzhnikov

unread,
Dec 6, 2007, 11:57:22 PM12/6/07
to
aj <a...@bookac.com> writes:

> 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.

aj

unread,
Dec 7, 2007, 11:01:48 AM12/7/07
to
On Dec 6, 11:57 pm, Paul Pluzhnikov <ppluzhnikov-...@charter.net>
wrote:

Thanks for the insight, Paul. I greatly appreciate it.

0 new messages