ReaderWriterLock - static declaration necessary?

  • Thread starter Thread starter Tryion
  • Start date Start date
T

Tryion

Hi,

I'd like to know if it's possible/responsible to use the ReaderWriterLock
class (RWL) in a class without declaring it as "static". The example in the
SDK does not use a static RWL. However, the documentation has the standard
disclaimer of "Any public static members of this type are safe for
multithreaded operations. Any instance members are not guaranteed to be
thread safe." And the members of this class are not static, so all of
ReaderWriterLock methods are unsafe for multithreaded operations? Seems
like RWL is not terribly useful! Should I assume the docs are wrong?

I can make the instance of the RWL class static in the class containing it,
which I believe will have approx. the same effect as making the methods
static (at least for operations between the instances of the containing
class)? Moreover, the example at (
http://msdn.microsoft.com/library/d...SystemThreadingReaderWriterLockClassTopic.asp )
, it indicates that declaring the ReaderWriterLock static makes it visible
to all threads. Which implies it's not visible if it's not static? <blink,
blink>

Any insight into the behavior of RWL would be helpful - any links to
articles, ect. would be much appreciated. I've found a few articles on the
subject, but none go into enough detail into the inner workings of RWL to be
of much help. I'm thoroughly confused.

Regards,
Tyrion
 
Tryion said:
I'd like to know if it's possible/responsible to use the ReaderWriterLock
class (RWL) in a class without declaring it as "static". The example in the
SDK does not use a static RWL. However, the documentation has the standard
disclaimer of "Any public static members of this type are safe for
multithreaded operations. Any instance members are not guaranteed to be
thread safe." And the members of this class are not static, so all of
ReaderWriterLock methods are unsafe for multithreaded operations? Seems
like RWL is not terribly useful! Should I assume the docs are wrong?

I think so - there are other places where that doc comment appears
despite other documentation saying it's fine.
I can make the instance of the RWL class static in the class containing it,
which I believe will have approx. the same effect as making the methods
static (at least for operations between the instances of the containing
class)?

No, that won't have the same effect at all. It's a property of the
methods themselves as to whether or not they're thread-safe, not
whether or not a variable containing a reference to an instance is
static or not.

Moreover, the example at (
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemThreadingReaderWriterLockClassTopic.asp )
, it indicates that declaring the ReaderWriterLock static makes it visible
to all threads. Which implies it's not visible if it's not static? <blink,
blink>

I think that's just a very poor doc comment, really. It has to be
static because everything's static! No instances are created...
 
Thanks for the info, John. Good to know I'm not the only one confused by
the docs, at least. I'm going to go ahead and use a non-static
declaration. But I'm feeling the need to test it more than I was originally
planning to. If I find anything, errrr- interesting, I'll post it. <g>
 
Back
Top