Continous thread ids

Terry Lambert tlambert2 at mindspring.com
Thu Nov 27 01:38:04 PST 2003


"sapdb at komadev.de" wrote:
> i wrote a little thread test programm. when i run it i get an output like
> ...
> 10 of 10 threads running, i am 0x8069000
> 10 of 10 threads running, i am 0x806c000
> 10 of 10 threads running, i am 0x806f000
> ...
> 
> is there a generic way (not kse dependant), to get a still unique countinous
> thread id starting with 1,2 .... n ? With linuxthreads, it was possible by a
> dirty hack, masking out the upper 20 bit, but that seems not to be the way its
> meant to work huh ?
> 
> any ideas ?

I think you meant "monotonic"/"contiguous"/"corresponding"?

The answer is that the thread ID is an opaque value that belongs
to the implementation, and you can not rely on its range or domain,
so it's not possible to do things like create an array and index it
by thread ID.

I think the correct data structure for what you want, and which is
not implementation dependent, is probably a hash table.

-- Terry



More information about the freebsd-threads mailing list