Subj : Re: Challenge: Multithreading & Synchronization To : comp.programming.threads From : David Schwartz Date : Fri May 20 2005 08:39 pm "Uenal Mutlu" <520001085531-0001@t-online.de> wrote in message news:d6m355$uut$04$1@news.t-online.com... >> SMP-safe operations are hugely >> expensive on P4s, and hiding the expense inside unseen magic is bad. > So what's your proposed workaround? Let me guess: the mighty MFENCE, > right? > Why don't you think that the InterlockedXXX func already could make use of > it on CPUs which have it? > And, is this statement anyhow related to the original question? No, my preference is simply to use the most efficient mutex provided by the platform. > Here is another example of your such totally unrelated and IMO wrong > answer: > (this is from the other thread): > If you think I'm wrong, prove it. Present an implementation of a > recursive mutex such that it can't be made significantly less expensive by > making it non-recursive. I'll even ignore the overhead of the extra > locks/unlocks, I'm only concerned with the cost of the first lock and the > first unlock. If you can do it, I will call you a genius. Prove it. Present the implementation without huge blocks of "magic here that I'm not going to show you". I claim that you cannot make recursive mutexes as efficient as non-recursive ones unless you cripple the non-recursive mutexes deliberately. A recursive mutex will have to determine that this unlock requires the mutex to actually be released. This cannot easily be done without either an extra interlocked operation, per-thread data for the mutex, or hiding the costs elsewhere by making the lock operation complex and bizarre. All you have done is, at best, reimplement spinlocks *very* badly. Badly because, among other things, contending threads will chew up the front-side bus, making it harder for the thread that has the lock to finish its job. You are going to have to make every mistake until you get things right. That's fine, I had to do the same thing. But don't tell other people what to do when you don't know yourself. DS .