Skip to content

Commit

Permalink
Disable spinlocks
Browse files Browse the repository at this point in the history
Now that c++11 branch has been merged in master,
disable unconditionally the spinlocks and use mutex
instead. This will allow to run fishtest even on HT
machines withouth changes.

In the future we will reintorduce spinlocks, once
we will have took care of fishtest.

No functional change.
  • Loading branch information
mcostalba committed Mar 2, 2015
1 parent 6645115 commit cb2111f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 4 deletions.
2 changes: 1 addition & 1 deletion src/thread.h
Expand Up @@ -39,7 +39,7 @@ const size_t MAX_THREADS = 128;
const size_t MAX_SPLITPOINTS_PER_THREAD = 8;
const size_t MAX_SLAVES_PER_SPLITPOINT = 4;

#if !defined(NO_SPINLOCK)
#if 0
/// Spinlock class wraps low level atomic operations to provide a spin lock

class Spinlock {
Expand Down
3 changes: 0 additions & 3 deletions src/types.h
Expand Up @@ -31,9 +31,6 @@
/// -DNO_PREFETCH | Disable use of prefetch asm-instruction. You may need this to
/// | run on some very old machines.
///
/// -DNO_SPINLOCK | Use mutex instead of spinlocks. This is much slower, so you
/// | really don't want to do this in general case.
///
/// -DUSE_POPCNT | Add runtime support for use of popcnt asm-instruction. Works
/// | only in 64-bit mode and requires hardware with popcnt support.
///
Expand Down

1 comment on commit cb2111f

@lucasart
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to revert spinlocks. There is a fix, proposed by Ronald de Man, that requires no distinction between HT and non HT. Simply add _mm_pause() from <immintrin.h>:

void acquire() {
    while (lock.fetch_sub(1, std::memory_order_acquire) != 1)
        while (lock.load(std::memory_order_relaxed) <= 0)
            _mm_pause();
}

Edit: I've opened a pull request, with the fix and test results.

Please sign in to comment.