From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,a3ae14aeae49226 X-Google-Attributes: gidfee84,public From: Dirk Grunwald Subject: Re: mutex between processes? Date: 1998/08/05 Message-ID: #1/1 X-Deja-AN: 378229849 References: <35C85511.E31EBB9E@brighttiger.com> Organization: University of Colorado Newsgroups: comp.unix.osf.osf1 Jeff Denham writes: > Sorry to disappoint on another front: a PSHARED implementation > is probably going to make a system call when there's contention > on the mutex. With no contention, the thread can lock and > go, but with contention, it's probably going to block in the > kernel, and that takes a system call. -- But, in a 'mmap' region, you can also use the native spinlock/critical section mechanisms. These will differ from machine to machine. For the alpha, the easiest way to construct an atomic spinlock would be to use the API provided in /usr/include/alpha/bulitins.h. E.g., a lock acquire would be: acquire(volatile int *addr) { /* Spin, waiting for location to be available */ for(;;) { while (*addr != 0); if ( __ATOMIC_EXCH_LONG(addr, 1) == 0 ) { break; } /* might not be needed, ya never know and you're not doing much else right now anyway.. */ __MB(); } } release(volatile int *addr) { *addr = 0; __MB(); } -- Dirk Grunwald Assoc. Prof, Univ. of Colorado at Boulder