Quote:
Originally Posted by
Corona688
As I suspected it would, pthread_getspecific
uses THREAD_SELF anyway -- and that's only in the
best case. Worst case it has to plunge in and access other thread memory other ways.
Thanks for the heads-up Corona688,
You might be right, but the thing is I had to store the "pthread_t" values in an array anyway, so in my application, after calling pthread_self() I would then always have to search the array for the corresponding "pthread_t" value. (At the moment this search is O(n) but I had planned to get it down to O(log n) using a binary-search algorithm if the number of threads is "high").
The good thing about "pthread_getspecific" is it returns the actual data I wanted, but as you pointed out, it looks a bit "involved" when it's not the best case. Maybe I'll try both approaches and see which is quicker.
Using "pthread_getspecific" might be better in avoiding a cache colision though, rather than threads accessing data in a global table.
Quote:
Stop trying to be so clever and just use pthread_self, that's what it's there for
Trying to be clever ain't so bad if I can manage to pull it off now and again