FreeBSD spinlock

Orit Moskovich oritm at
Tue May 7 07:05:00 UTC 2013


I read a bit about the FreeBSD mutex implementation for spinlock.
I might be wrong, but I noticed a code section that might be problematic:

Taken from

static inline void
spin_lock_init(spinlock_t *lock)

        memset(&lock->m, 0, sizeof(lock->m));
        mtx_init(&lock->m, "lnxspin", NULL, MTX_DEF | MTX_NOWITNESS);

But MTX_DEF initializes mutex as a sleep mutex:

By default, MTX_DEF mutexes will context switch when they are already


There is a flag MTX_SPIN Which I think is the right one in this case .

I'd appreciate your take on this issue.


Orit Moskovich

More information about the freebsd-questions mailing list