RE: Panic in OSMalloc??
RE: Panic in OSMalloc??
- Subject: RE: Panic in OSMalloc??
- From: "Vishal Shetye" <email@hidden>
- Date: Fri, 11 Jan 2008 22:35:15 +0530
Hi Mike,
Thanks for your comments.
Actually, I'm in bug-fixing phase and changes in the code would require
thorough testing.
I would be doing some changes as per suggestions in this thread.
But still if you could clarify a few things -
- Is there any specific reason that I see panic only on iMac(10.4.8) and
not on MacPro(10.4.9) or MacMini(10.4.7)?
- what are the consequences of sleeping while holding a lock?
________________________________
Thanks
- vishal shetye
-----Original Message-----
From: Michael Smith [mailto:email@hidden]
Sent: Friday, January 11, 2008 10:20 PM
To: Vishal Shetye
Cc: email@hidden
Subject: Re: Panic in OSMalloc??
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