Re: Holding a spinlock
Re: Holding a spinlock
- Subject: Re: Holding a spinlock
- From: Shantonu Sen <email@hidden>
- Date: Tue, 06 Sep 2016 15:09:15 -0700
None of the constraints of kernel synchronization apply to user mode synchronization.
Hand-rolled spin locks can be faster and have reduced storage than pthread mutexes, however they frequently also have either reduced functionality (like priority propagation, owner detection, correctness assertions, recursive acquisition) and worst-case performance (unfairness, CPU usage under contention, inversions under system load).
Unless you can characterize these all, you likely should not be writing your own locks except as an experiment.
Shantonu
> On Sep 6, 2016, at 2:30 PM, Adriaan van Os <email@hidden> wrote:
>
> Shantonu Sen wrote:
>> What are you actually trying to do?
>> If you want to acquire a lock and then execute code in the critical section which might block, you should use a mutex. On x86, kernel mutexes have an adaptive spin before they block on contention, so in practice critical sections of a few instructions should not cause other contending threads to enter the scheduler.
>
> I am just curious to know all the implementation details. I did some tests (in user code) with various locking/atomic methods and noticed that OSSpinlocks are extremely fast, a zillion times faster than pthread mutexes. I am writing a (user code) OSSpinlock equivalent that uses a 1-byte (or 1-bit) flag rather than a 4-byte spinlock. And want to make it as fast as possible.
>
> Regards,
>
> Adriaan van Os
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden