473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1696
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 necessary and it is not the practice in C++. Static...
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; try {
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 unhandled exception if I acquire a WriterLock with...
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, etc.) the code then loads the variable from source...
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 globalMixed4 {
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 declaration rather than a definition. As I've...
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 declared static instead classes 4. objects declared...
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 without an initializer. I tried it using Visual...
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 like this in the header file: typedef struct...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.