Subj : Re: What is the real costs of LOCK on x86 multiprocesor machine? To : comp.programming.threads From : Joe Seigh Date : Sat Jul 30 2005 08:28 am Mirek Fidler wrote: > Well, I guess that I should have been be more specific: > > If accessed memory is contained exclusively in one CPU cache, is it true > that LOCK penalty is lower than 100-200 cycles? > > My question is mostly about reference counted shared objects (e.g. in > C++). What I want to find out is whether penalty is present in all > cases, or whether when only single thread "owns" shared data (reference > count is not accessed by other threads), penalty is lower. > > Unfortunately, at the moment I do not have hardware to test... > You can measure cache hits. Just sequentially access more memory than can fit in your cache. Brute force will work if you don't want to figure out the n-way associative hashing and stuff. You'll have to figure out the contention factor which would be dependent on the number of cpus. If it's a problem there are more cache friendly algorithms out there though it would be much better if the cache coherency protocols weren't stuck back in the 70's and 80's as far as threaded programming was concerned. -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .