Subj : Re: Challenge: Multithreading & Synchronization To : comp.programming.threads From : doug Date : Tue May 24 2005 12:09 am "David Schwartz" wrote in message news:d6t6df$auh$2@nntp.webmaster.com... > > "doug" wrote in message > news:ZyPje.1900$iq5.1180@fe1.news.blueyonder.co.uk... > >> I know where you're coming from - that's where I came from too. But some >> folk (Peter, Giancarlo) explained that *yes*, you might read the wrong >> value, but it doesn't matter. You're guaranteed to get the answer to the >> question "do I own this lock" correct. > > Guaranteed by what? > > Suppose you are thread "A1". The lock is held by "A2" and transfers to > "B1" while you are checking the owner field. What stops you from seeing > half of each and getting "A1", and thinking you own the lock? > > DS > > Ah, good point. Very good point indeed. I think we're assuming that reads/write of an owner field would be atomic. But bloody good point. I remember one of our Uni profs. once told us 'never ever ever read a shared value without some kind of memory barrier work, even if you don't really care about the result'. I thought I'd been shown an exception to his rule, but maybe his rule holds if you want your recursive mutex to be completely portable, and not rely on any special property of reading/writing an 'owner' field. Thoughts? Doug .