473,804 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ReadersWritersL ock 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 ReadersWritesLo ck with a slight
twist in My unmanaged C++. I can not import "System" and "System.Threadi ng"
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 1157
MJS_Jeff wrote:
I am seeking the solution to the classic ReadersWritesLo ck with a slight
twist in My unmanaged C++. I can not import "System" and "System.Threadi ng"
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 ReadersWritesLo ck with a slight
twist in My unmanaged C++. I can not import "System" and "System.Threadi ng"
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******@discu ssions.microsof t.com> wrote in message
Any Ideas and suggestions is greatly appreciated.


Take a look at "Programmin g 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
2860
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. To adapt to C#, I've wrapped the older DLL calls in an unmanaged C++ class which pretty much just parallels the original function calls and encapsulates the more ragged aspects (handles, etc). Then in turn, I wrapped the unmanaged C++ class...
4
2434
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 collection is not used in this class. (singleton class + override InitializeLifetimeService ) The service class uses C++ unmanaged function from dll (using DLLimport).
2
1334
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 have to use it on more than one computer but most of the time I will be using my own computer. If, unmanaged code is faster, than what would I have to do to switch between managed and unmanaged code? Can I just change a simple setting on the new...
4
1664
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 program. I want to write a C# DLL file where I can call methods from the C++ program so that it can get data out of the database. The C++ program is only needing to get a few things from the database so it's going to be simpler to just use C# for...
2
9508
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 to do that? Thanks. Tsung-Yu
0
3908
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 dllmodul.cpp(102) similar to what is mentioned below)... I am calling MFC as part of unmanaged code used by the managed code. +--------
0
2063
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
1886
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 statements near the top of the file. These headers contain older unmanaged class declarations. When running I discovered a new bug, a crash, at a point in execution that was nowhere near any code that's been touched in quite a while. After hunting down...
0
853
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. The class sent to us can not be compiled as managed code so I have built a managed wrapper class... here is the general code #using <mscorlib.dll> #pragma once
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10089
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9171
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.