Re: IOMalloc / IOFree while holding a mutex
Re: IOMalloc / IOFree while holding a mutex
- Subject: Re: IOMalloc / IOFree while holding a mutex
- From: Michael Crawford <email@hidden>
- Date: Wed, 16 Nov 2011 07:10:13 -0800
> On Wed, 16 Nov 2011 11:09:07 +0530 (IST)
> sheetal phirke <email@hidden> wrote:
>
>> Can I call IOMalloc / IOFree while holding mutex lock?
>
> yes.
I expect that the reason you can do that is that attempting to acquire
a mutex lock can block. Spinlocks are much faster than mutexes
because they never block. You never have to worry about context
switch time.
But if you are blocked when some other thread tries to acquire the
same spinlock that you are holding, it might hold that spinlock for a
very long time, until your call to IOMalloc or IOFree returns.
Because spinlocks just waste CPU cycles until the spinlock object is
acquired, doing this will waste CPU resources in a dramatic way.
It will also slow everything else down in the system, even if not
CPU-bound, because all the tasks that depend on spinlock acquisition
are designed with the assumption that it never takes very long to
acquire one.
--
Michael David Crawford
mdcrawford at gmail dot com
Custom Software Development for the iPhone and Mac OS X
http://www.dulcineatech.com/custom-software-development/
_______________________________________________
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