From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII X-Google-Thread: fee84,a3ae14aeae49226 X-Google-Attributes: gidfee84,public From: Jeff Denham Subject: Re: mutex between processes? Date: 1998/08/07 Message-ID: <35CB2911.61856927@brighttiger.com>#1/1 X-Deja-AN: 378885593 Content-Transfer-Encoding: 8bit References: <35C85511.E31EBB9E@brighttiger.com> <35CAC907.497400F4@orga.com> Content-Type: text/plain; charset=iso-8859-1 X-Trace: newsreader.digex.net 902506691 207.86.119.34 (Fri, 07 Aug 1998 12:18:11 EDT) Organization: Bright Tiger Technologies MIME-Version: 1.0 NNTP-Posting-Date: Fri, 07 Aug 1998 12:18:11 EDT Newsgroups: comp.unix.osf.osf1 Aurel Balmosan wrote: > Dirk Grunwald wrote: > > > But, in a 'mmap' region, you can also use the native spinlock/critical > > section mechanisms. These will differ from machine to machine. > > > > Does it work also on shared memory (I would guess so)And what about DEC-Alpha > with lets say 12 processors? > > > /* might not be needed, ya never know and > > you're not doing much else right now anyway.. */ > > __MB(); > > > > What is that? What does a Memory Barrier do and why is it needed? Yes, the spinlock approach will work in any support form of shared memory. Whether a spinlock is appropriate for your app depends on the size/duration of your critical sections. If you'll have lots of contention of the lock or the lock is held for "long" periods, then the system call is a win. There's a crossover point where spinning no longer pays off. The __MB() (memory barrier) is *absolutely* necessary for the spinlock to work on an MP system. In Dirk's example, though, I'm pretty sure that the __MB() in the release() routine is in the wrong place -- it should be before the clearing of the lock, not after. This guarantees that the updates to the object being locked are seen by other processors before they see that the lock is clear, grab it, and see stale state in the object. The more aggressive your memory subsystem is at optimizing (i.e., reodering) its traffic to main memory (can you say 21264?), the more quickly your missing or misplaced memory barriers will screw you. Jeff __________________________________________________ Jeff Denham (jdenham@brighttiger.com) Bright Tiger Technologies SmartCluster� Software for Distributed Web Servers http://www.brighttiger.com 125 Nagog Park Acton, MA 01720 Phone: (978) 263-5455 x177 Fax: (978) 263-5547