From: Dirk Grunwald <grunwald@foobar.cs.colorado.edu>
Subject: Re: mutex between processes?
Date: 1998/08/05 [thread overview]
Message-ID: <qxpww8nuyph.fsf@foobar.cs.colorado.edu> (raw)
In-Reply-To: 35C85511.E31EBB9E@brighttiger.com
Jeff Denham <jdenham@brighttiger.com> 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
next prev parent reply other threads:[~1998-08-05 4:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-08-04 4:00 mutex between processes? Aurel Balmosan
1998-08-05 4:00 ` Jeff Denham
1998-08-05 4:00 ` Dirk Grunwald [this message]
1998-08-07 4:00 ` Aurel Balmosan
1998-08-07 4:00 ` Jeff Denham
1998-08-07 4:00 ` Aurel Balmosan
1998-08-07 4:00 ` Monty Brandenberg
1998-08-09 4:00 ` Aurel Balmosan
1998-08-10 4:00 ` Dirk Grunwald
1998-08-10 4:00 ` Monty Brandenberg
1998-08-10 4:00 ` Dirk Grunwald
1998-08-10 4:00 ` Monty Brandenberg
1998-08-11 4:00 ` Aurel Balmosan
1998-08-11 4:00 ` Monty Brandenberg
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox