Re: Holding a spinlock
Re: Holding a spinlock
- Subject: Re: Holding a spinlock
- From: Shantonu Sen <email@hidden>
- Date: Tue, 06 Sep 2016 09:58:46 -0700
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.
Shantonu
> On Sep 3, 2016, at 5:44 PM, John Kraft <email@hidden> wrote:
>
>
> We use IOSimpleLocks from the IOKit for this. These are just wrappers around the lck primitives, though.
>
>
> ________________________________________
> From: darwin-kernel-bounces+jfk=email@hidden <darwin-kernel-bounces+jfk=email@hidden> on behalf of Adriaan van Os <email@hidden>
> Sent: Saturday, September 3, 2016 2:13 PM
> To: email@hidden
> Subject: Holding a spinlock
>
> The Kernel Programming Guide in the Synchronization Primitives chapter says the following in the
> Locks section, Spinlocks subsection
>
> Note that a thread may not block while holding a spinlock, because that could cause deadlock.
> Further, preemption is disabled on a given processor while a spinlock is held.
>
> I assume the code will be something like (in Linux <http://www.makelinux.net/books/lkd2/ch06lev1sec7>)
>
> local_irq_disable();
> spin ....
> local_irq_enable();
>
> However, I haven't been able to locate the code that does this or similar, at least not in
> osfmk/kern/locks.c. What is the recommended practice on Mac OS X ? I mean, apart from using the
> lck_ functions, who are not practical to use in my case.
> _______________________________________________
> 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
_______________________________________________
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