Re: race on multi-processor solaris

From: Jonathan Adams (jonathan-ggl_at_ofb.net)
Date: 12/08/03


Date: 8 Dec 2003 02:08:30 -0800


"David Schwartz" <davids@webmaster.com> wrote:
> "Logan Shaw" <lshaw-usenet@austin.rr.com> wrote in message
> news:GLYyb.72566$Ek.30545@twister.austin.rr.com...

> > Also, since this discussion is cross-posted to comp.unix.solaris,
> > doesn't Solaris have an adaptive mutex implementation? If I understand
> > correctly, this means that on a two CPU Solaris machine, the version
> > with locks will also have the loser thread spinning and waiting for
> > the resource to come free. If it doesn't within a period of time,
> > only then will the thread be put to sleep. So, the version with
> > locks will suffer some of the same CPU wastage as the lock free version.

There is a difference -- adaptive mutexes spin with non-atomic operations,
lock-free algorithms spin with atomic ops. The bus traffic is much lighter
with the non-atomic operations.

> Not if the adaptive mutexes adapt correctly. Sufficient contention
> should cause the mutex to adapt and block. Once the mutex blocks once, the
> thread that can run without contention will use up a full timeslice. The big
> loss only happens when both threads continue blundering through the
> contention for all or most of their timesilces.

Solaris' adaptive mutexes spin (reading the mutex using non-atomic ops)
as long as the thread holding the lock is running on a CPU. There are a few
reasons for this:

    1. critical sections should be short, so you shouldn't be spinning
        for very long.
    2. context switches are expensive, compared to lock aquisition.
    3. it simplifies the interactions with the thread unlocking the mutex.

If the owner goes to sleep, any waiters will stop spinning and block.

- jonathan



Relevant Pages

  • Re: [Patch] C1X threading support
    ... which it has to do if the mutex is to do anything useful. ... performed before the lock is released are visible before any CPU can ... If this isn't done then a CPU can read a value 'protected' ... all that you have to guarantee for an assertion of this ...
    (freebsd-arch)
  • Re: Response issues on GS1280, VMS 7.3-2
    ... the primary CPU in interrupt state ($MONITOR MODES/ALL could help check ... any slow I/O devices tend to build up lock queues. ... The processes in MUTEX range widely, ... ES45s can have at most 4 CPUs and their path to memory is quite short, ...
    (comp.os.vms)
  • Re: [Patch] C1X threading support
    ... While the current thread holds the lock, ... CPU, the mechanics of migrating to another CPU will use sufficient ... all that you have to guarantee for an assertion of this ... state when the mutex is locked and will look like something else when the ...
    (freebsd-arch)
  • Re: pthread_mutex_trylock vs. pthread_mutex_lock
    ... only suitable for multiple CPU. ... try_to_lock() - means you pooling lock. ... Try to take over mutex, ... On single CPU ThreadA must yield CPU so if thread B ...
    (comp.programming.threads)
  • Re: Mutex Question
    ... where every time its pre-empted out of the CPU the lock is always with ... But I agree to the fact that if the context switch takes place on ... starving the order process for the mutex would not help much. ...
    (comp.unix.programmer)