1 Apr
2013
1 Apr
'13
9:35 a.m.
Actually you don't need a per-thread counter, only per-cpu (see sched_getcpu()/getcpu()), although I'm not sure it'd be as fast as using thread-register like Trent does.
Of course, per-cpu only holds for kernel-space, in userland you could get preempted... So you'd need O(number of threads) counters per object (and allocating them on demand will probably kill performance). cf