site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com If funcB has to be callable unlocked somewhere, then: funcA() { lock mutex funcB_locked() do stuff... unlock mutex } funcB() { lock mutex funcB_locked() unlock mutex } /* MUST be called with mutex held! */ funcB_locked() { do stuff... } -- Terry Terry, Thanks for the explanation. funcA() { lock mutex funcB() do stuff... unlock mutex } funcB() { lock mutex do stuff... unlock mutex } Cheers, Erez On Jul 19, 2007, at 7:24 AM, Terry Lambert wrote: Hi, 10.4.9+ 10.5 How do I obtain a Kernel Recursive mutexe? The available api does not support this. lck_mtx_alloc_init(gmutex_grp_m, LCK_ATTR_NULL) some function(object) lock mutex atomic increment reference count unlock mutex ... long duration operation ... lock mutex atomic decrement reference count unlock mutex ... destroy(object) lock mutex again: /* Don't destroy the object while someone is using it */ if reference count msleep(mutex, object) goto again /* avoid race */ /* last reference gone, OK to kill it */ destroy object unlock mutex //====================== Erez Kaplan Senior software engineer OSX erezk@speedbit.com //====================== _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... We do this sort of thing in the kernel in a number of places, where reference counts would be inappropriate. On Jul 18, 2007, at 9:36 PM, Erez Kaplan wrote: I am facing a some what strange sequence of calling (forced by PC porting) which looks something like this: Currently I get a deadlock situation. How would you outline handling this deadlock? On Jul 18, 2007, at 8:54 PM, Erez Kaplan wrote: On Jul 18, 2007, at 10:00 PM, Terry Lambert wrote: On Jul 18, 2007, at 2:37 AM, Erez Kaplan wrote: You don't; this is what reference and use counts are for. Can you explain a bit more or give reference to an example. For example, all thread reentrant FSs will take an I/O reference on a vnode, and use that reference to prevent the FS from being unmounted out from under an operation in progress, rather than holding a lock over the complete operation (thus unnecessarily serializing all other I/O to the vnode). Here is a simplified design pattern: /* wake up destroy routine; destroy routine may fail acquisition race */ if !reference count wakeup(object) -- Terry This email sent to site_archiver@lists.apple.com