
Mark Sizer wrote:
You can do that with Windows thread IDs, because they are simple integers. Unfortunately the Posix thread ID type (pthread_t) is an abstract data type and the only relation defined on it is equality (pthread_equal()). Some implementations use a type that can safely and correctly be compared with std::less, but there's no guarantee of that, so Boost can't offer such a guarantee either.
How about using pointers to boost::thread objects as IDs (they must of course be the instances used to start the thread, rather than instances created with the default constructor). Store each thread's own pointer in TLS (or TSS as Boost.Threads calls it). (This is tricky, though - you can't pass a thread's own ID to its initial function, as threads start to run immediately. I suppose you could use placement new, but that's a bit gross.) What's the need for thread IDs, anyway? Are you using a thread pool?

William E. Kempf wrote:
Actually, we can, and do in the thread_dev branch. It means that the ID is of implementation defined type, but it's portable.
In the mean time I would probably do something like the following:
(obviously it needs a bit of fleshing out)
template<class T> class thread_map
{
class wrapper;
public:
typedef const wrapper* id;
id create(const boost::function1
participants (4)
-
Ben Hutchings
-
Mark Sizer
-
Sam Partington
-
William E. Kempf