Subj : Re: Lockable objects To : comp.programming.threads From : doug Date : Sat May 21 2005 12:04 pm "Uenal Mutlu" <520001085531-0001@t-online.de> wrote in message news:d6n4br$a5t$03$1@news.t-online.com... > "Giancarlo Niccolai" wrote >> Uenal Mutlu wrote: >> >> > I'm predicting that in the near future all non-trivial objects the >> > programming language offers (esp. C++ & STL) will have >> > some built-in synchronization methods for the user, like: >> > Lock() >> > Unlock() >> > TryLock() >> > IsLocked() >> > GetLockCount() >> > And most probly the locking will be done by using recursive mutices >> > internally. >> >> Mutulu, are you really serious? >> It's on the first page of any threading book! >> >> if ( IsLocked(X) ) { >> <<< Here another thread locks X >>> >> // do something believing X is not locked >> // and bang. >> } > > I don't know why you would do this. > >> That's why no-one ever implemented an IsLocked primitive. > > Obviously with very good reason. > >> I am beginning to suspect you are a troll; so, please, are you SERIOUS >> about >> threading or are you making jokes of us? > > I don't know what your problem is, I've always been serious. > The IsLocked() is only to query whether the mutex is currently locked. > It is an information about the state of the mutex. But what use is that information? It's 'out of date' as soon as you get it. You can't seriously use isLocked anywhere (except diagnostics, but you can't even trust those fully). > For actual locking one uses the Lock() method. > > .