Re: Panic in OSMalloc??
Re: Panic in OSMalloc??
- Subject: Re: Panic in OSMalloc??
- From: Michael Smith <email@hidden>
- Date: Fri, 11 Jan 2008 08:49:40 -0800
On Jan 10, 2008, at 11:15 PM, Vishal Shetye wrote:
Could you please explain what are the consequences of calling
OSMalloc with
some spin lock held.
I'm using lck_spin_lock() to lock a global variable before OSMalloc
and
release it once the item allocated has been added to a queue.
Why would you do this?
Firstly - spinlocks are a low-level primitive; they are not generally
suitable for use in high-level code. At the level you are working,
you should almost never need a spinlock - use a proper mutex if you
must, but strive whenever possible to design your code so that you
don't need locking in the first place.
Secondly; why are you locking the global and then blocking? You
should be using a try/backout scheme to avoid holding the lock while
you sleep:
LOCK
flag = condition
UNLOCK
if (flag)
thing = allocate()
LOCK
if (!condition)
do_free = true
else
do_free = false
queue_enter(thing)
endif
UNLOCK
if (do_free)
free(thing)
endif
endif
= Mike
_______________________________________________
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