Subj : Re: recursive mutexes To : comp.programming.threads From : Giancarlo Niccolai Date : Sun May 15 2005 02:24 pm Uenal Mutlu wrote: > >> >> In all the years I've been programming, I have never used a recursive >> mutex (except in Java, but that's another story). > > Then you must have overlooked their real value. Sorry if I jump in late in the discussion, but I believed that David was enough to fix this mental bug that you have encountered. IMHO usage of recursive mutexes is generally an immediate and incontestable proof of poor design. It's not a matter of multithreading theoremes, it's a matter of parallel activity design. Coordination is an high level activity in any parallel process, be it coordination between firm divisions, production chains, information processing or simply programming. You don't want a magazine clerk of the production function to coordinate with a magazine clerk of the provisions. The production manager will raise the phone and talk with the provision manager (or the other way around) when they need coordination. And believe me, they both know when they take up the phone (lock) and when they put it down (unlock), and it's unlikely that they can raise the phone twice without lowering it first. Same for threads. When threads need coordination, a well designed system will put this coordination in a place that each thread can perfectly manage, and will make sure that coordination will 1) take less time and computational power as possible and 2) nothing else will be done during coordination step. Locking a mutex means your agents are phoning each other. It's not polite to have listener(s) hanging because you must do something while phoning them, even if this something is somehow a recursive function call. Locking for everything else except coordination (that is, inter-thread communication) is bad design. Not just bad programming, but bad understanding of parallel processing logic. Bests, Giancarlo Niccolai. .