472,347 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,347 software developers and data experts.

ReaderWriterLock - static declaration necessary?

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/de...ClassTopic.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
Nov 15 '05 #1
2 1633
Tryion <Tyrion@_nowhere_.com> wrote:
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/de...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...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
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>
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Bryan Parkoff | last post by:
I have noticed that C programmers put static keyword beside global variable and global functions in C source codes. I believe that it is not...
2
by: pokémon | last post by:
Question: Is this thread-safe: ReaderWriterLock rwl = new ReaderWriterLock(); Queue q = new Queue(); public int GetCount() { int val = 0;...
4
by: Anders Borum | last post by:
Hello! I am working on improving my threading skills and came across a question. When working with the ReaderWriterLock class, I am getting an...
1
by: fm | last post by:
I have a public shared property in global.asax. When the variable of the property is not instantiated (first page to call it, cache empties,...
9
by: Christian Christmann | last post by:
Hi, I have problems to initialize a static struct. Here is the meaningful part of the code: int main() { int pA = -100; struct...
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object...
9
by: t | last post by:
Lippman's C++ Primer says that if you initialize a const static data member in a class, you still need to define the member outside the class but...
11
by: Jef Driesen | last post by:
I have the following problem in a C project (but that also needs to compile with a C++ compiler). I'm using a virtual function table, that looks...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.