[Courses] comparing threads
Kathryn Hogg
kjh at flyballdogs.com
Sat Feb 9 19:12:48 EST 2002
> Hi all, how do one compare thread ids? (without overloading the
> comparison functions...that'll be too much) I just realised that the
> operands cannot compare type pthread_t, and I'm having a hard time
> figuring it out since I need to compare thread id to a table of ids
> (comprised of linked list). Any suggestion? --Rei
memcmp?
pthread_t *tid1 = ....;
pthread_t *tid2 = .....;
if (memcmp(tid1, tid2, sizeof(pthread_t) == 0) {
cout << "they are equal" << endl;
} else {
cout << "they are not equal" << endl;
}
of course, I would just overload in C++:
inline bool operator == (const pthread_t &t1, const pthread_t &t2)
{
return memcmp(&t1, &t2) == 0;
}
--
Kathryn
More information about the Courses
mailing list