Subj : Re: CMPXCHG timing To : comp.programming.threads From : Joe Seigh Date : Sat Apr 02 2005 05:11 am On 1 Apr 2005 22:17:47 -0800, Michael Pryhodko wrote: >> Could you try stating what you're trying to do in simple terms? > > I am trying to implement on x86 "lock" object according to formalized > algorithm I described in other post. I've described more than once what > I am trying to do. Just read carefully my other posts. > It's hard to figure out sometimes what code is supposed to do even when it does work. On the basis that you're trying to implement a "lock" and seem to not want to use the interlocked hardware primatives, I would guess at this point you are trying to implement a lock using a distributed algorithm. Distributed algorithm is a formal term and is where threads read other thread's storage but not write to it. Known distributed algorithms for locking include Dekker's algorithm and Peterson's algorithm. You should study those algorithms first and learn how they work. Note that any write up on them will assume a totally ordered memory model and you'll have to use the proper memory barriers in any implementations you do. Distributed algorithms aren't generally used as they don't perform as well as the hardware primatives that you are trying to avoid. The only place they're used is on very large systems with lot's of processors where the hardware primatives don't work, don't scale, or don't exist. -- Joe Seigh .