473,320 Members | 1,829 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,320 software developers and data experts.

ReadersWritersLock in an unmanaged C++ program.

Folks, I have posted this message on a different newsgroup but I did not get
a single response. I take it that it must not have been the right forum.
Anyways.

I am seeking the solution to the classic ReadersWritesLock with a slight
twist in My unmanaged C++. I can not import "System" and "System.Threading"
namespaces.

I need to use some kind of lock (semaphore, Mutex, or any other
alternative), among threads to alow multiple threads to use the shared
resource.
The threads will have either the "Reader" role or the "Writer" role.
As long as a the thread is a "Reader", and no "Writer" thread is holding
the lock or
waiting on the lock the Reader thread can proceed.
Multiple "Readers" can access the resource while there is no Writer.
Once a Writer enters the queue for the Wirte access, no new Reader will be
allowed to get the lock and it will encounter a timeout reject return value.
However, every previously entered Reader is allowed to complete its
operations until all releases its lock.
When no more Reader is pending, the Writer starts its
operation at the end of which it and then releases the lock. At this time
new Readers will be successfull in aquiring the lock.
When the first Writer thread is pending or working, all subsequent Readers
and/or Writer threads shall get the timeout rejection.

I have looked into documents for Semaphore, Mutext and "Wait Operations" but
I am not sure the semaphore's count-down can help me implementing the
algorithm.

Any Ideas and suggestions is greatly appreciated.
--
--Jeff

Nov 17 '05 #1
3 1139
MJS_Jeff wrote:
I am seeking the solution to the classic ReadersWritesLock with a slight
twist in My unmanaged C++. I can not import "System" and "System.Threading"
namespaces.

I need to use some kind of lock (semaphore, Mutex, or any other
alternative), among threads to alow multiple threads to use the shared
resource.


I found this while googling with <reader-writer c++ synchronization>:
http://www.frostbytes.com/~jimf/pape...c/c++sync.html

Maybe "Fair-Share Readers/Writer Class" is what you need.

Nov 17 '05 #2
Thanks Mihajlo.
I will look in the articles. They appear to be informative.

--Jeff

"Mihajlo Cvetanovic" wrote:
MJS_Jeff wrote:
I am seeking the solution to the classic ReadersWritesLock with a slight
twist in My unmanaged C++. I can not import "System" and "System.Threading"
namespaces.

I need to use some kind of lock (semaphore, Mutex, or any other
alternative), among threads to alow multiple threads to use the shared
resource.


I found this while googling with <reader-writer c++ synchronization>:
http://www.frostbytes.com/~jimf/pape...c/c++sync.html

Maybe "Fair-Share Readers/Writer Class" is what you need.

Nov 17 '05 #3

"MJS_Jeff" <MJ******@discussions.microsoft.com> wrote in message
Any Ideas and suggestions is greatly appreciated.


Take a look at "Programming Applications for Microsoft Windows" book by
Jeffrey Richter
Chapter "Thread Synchronization Toolkit"

Vladimir.
Nov 17 '05 #4

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

Similar topics

5
by: _BNC | last post by:
I've been adapting an older unmanaged C++ legacy app to C#---with limited success. The original app made use of an older, but straightforward, C DLL that worked efficiently under the VC++ 6 model....
4
by: jarmopy | last post by:
Hi, I have made a service with C# and calling that service class from another C# program with remoting. (Referendes from the calling program) That service class is configured so that garpage...
2
by: Dave | last post by:
Hi, I'm writing a research simulation program and would like to write it in c++. It should be as fast as possible and am not sure if it makes a difference to use managed or unmanaged code. I will...
4
by: Grant Stanley | last post by:
Im writting a program in unmanaged C++, and want to access a MS SQL Database. I've done quite a lot of database access stuff in C# before so I'm wanting to use C# for the database access in the...
2
by: joye | last post by:
Hello, My question is how to use C# to call the existing libraries containing unmanaged C++ classes directly, but not use C# or managed C++ wrappers unmanaged C++ classes? Does anyone know how...
0
by: Frank Lopez | last post by:
Does anyone know if Microsoft generated a whitepaper on this topic? Does anyone know what the solution is? (meaning, eliminate the leak problem -- I am seeing three memory leaks from...
0
by: Frank Lopez | last post by:
My program structure is: 1. 2. 3. => manually does the crt-init and crt-terminate calls 4. -- this is accessed by the unmanaged C++ classes in (3) using LoadLibrary and FreeLibrary
1
by: knormand | last post by:
I have an older MFC C++ app with some new Managed C++ being thrown in. Recently I turned on the /clr flag for one of my old .cpp files. I then placed '#pragma unmanaged' just below my #include...
0
by: Rick | last post by:
We have an class sent to us by a vendor in a .h file. This class controls access to a subsystem for gathering data. Currently we are using C++ 6.0 to access this class. Now we want to move to .net....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.