site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com On Jan 10, 2008, at 11:15 PM, Vishal Shetye wrote: Why would you do this? 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 (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... 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. 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: This email sent to site_archiver@lists.apple.com