ReaderWriterLock - static declaration necessary?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tryion

    ReaderWriterLock - static declaration necessary?

    Hi,

    I'd like to know if it's possible/responsible to use the ReaderWriterLoc k
    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
    ReaderWriterLoc k 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/de...ClassTopic.asp )
    , it indicates that declaring the ReaderWriterLoc k 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


  • Jon Skeet [C# MVP]

    #2
    Re: ReaderWriterLoc k - static declaration necessary?

    Tryion <Tyrion@_nowher e_.com> wrote:[color=blue]
    > I'd like to know if it's possible/responsible to use the ReaderWriterLoc k
    > 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
    > ReaderWriterLoc k methods are unsafe for multithreaded operations? Seems
    > like RWL is not terribly useful! Should I assume the docs are wrong?[/color]

    I think so - there are other places where that doc comment appears
    despite other documentation saying it's fine.
    [color=blue]
    > 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)?[/color]

    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.

    [color=blue]
    > Moreover, the example at (
    > http://msdn.microsoft.com/library/de...us/cpref/html/
    > frlrfSystemThre adingReaderWrit erLockClassTopi c.asp )
    > , it indicates that declaring the ReaderWriterLoc k static makes it visible
    > to all threads. Which implies it's not visible if it's not static? <blink,
    > blink>[/color]

    I think that's just a very poor doc comment, really. It has to be
    static because everything's static! No instances are created...

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Tryion

      #3
      Re: ReaderWriterLoc k - static declaration necessary?

      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>


      Comment

      Working...