473,659 Members | 2,662 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to check if Monitor::Exit has been called

Ian
Monitor::Enter and Monitor::Exit must be called in pairs. Is there a way
to determine if Monitor::Exit has been called so that it does not get called
a second time? The psuedocode below illustrates a situation I would like
to implement. Essentially there are 2 monitors and the first monitor can be
released in 2 different locations. This sample codes uses a booleen
variable to make certain the first monitor is not released twice. My
question is, does .NET offer a better way to check if a monitor object has
already been released/exited?

Thanks,

Ian
Monitor::Enter( resource1.Objec t );
Monitor::Enter( resource2.Objec t );
bool bMonitor1IsActi ve = true;

try {
// ...uses resources locked by resource1.Objec t and resource2.Objec t ,
may throw exceptions...

Monitor::Exit( resource1.Objec t );
bMonitor1IsActi ve = false;

// ...excute code locked to resource2.Objec t , may throw exceptions...
}
catch( Exception ^pE ) {
// ... handle exception ...
}
finally {
if( bMonitor1IsActi ve )
Monitor::Exit( resource1.Objec t );
Monitor::Exit( resource2.Objec t );
}

Nov 10 '06 #1
2 1775
"Ian" <Ia*******@yahX X.comwrote in message
news:qk******** ************@we ber.videotron.n et...
Monitor::Enter and Monitor::Exit must be called in pairs. Is there a way
to determine if Monitor::Exit has been called so that it does not get
called a second time? The psuedocode below illustrates a situation I
would like to implement. Essentially there are 2 monitors and the first
monitor can be released in 2 different locations. This sample codes uses
a booleen variable to make certain the first monitor is not released
twice. My question is, does .NET offer a better way to check if a monitor
object has already been released/exited?
That's exactly what the lock keyword is for

lock (resource2)
{
lock(resource1)
{
// code that needs both
}

// code that only needs resource 2
}

-cd
Nov 10 '06 #2
Ian
Hello Carl,

Are you referring to the 'lock' class in the C++ support library? I just
found it in the online help and will take a look at it.

Thanks,

Ian
Nov 10 '06 #3

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

Similar topics

5
3845
by: bughunter | last post by:
Hi, Consider this code: ---- Monitor.Pulse(oLock); Monitor.Exit(oLock); ---- If a thread was waiting on oLock then will the current thread
5
2072
by: Ken Varn | last post by:
If I have a value type such as int that I want to protect in a multi-threaded situation, Is it safe to use Monitor::Enter(__box(value))? I am thinking that a different object pointer is generated each time and thus the protection is not insured. Is this true or not? Example: public _gc class MyClass { int Value;
8
1716
by: Michael Kennedy | last post by:
Hi, I have been looking into the claim that the keyword lock is not safe when exceptions are possible. That lead me to try the following code, which I think has uncovered a serious error in the .NET 2.0 framework. Note that this runs better, but not perfectly, on .NET 1.1. Note: The numbers are line numbers needed to match the callstack of the exception below.
6
2132
by: Clark Sann | last post by:
Can someone help me understand what object should be used as the lock object? I've seen some programs that use Monitor.Enter(Me). Then, in those same programs, they sometimes use another object. Why? I would appreciate it if someone could help me understand the ramifications of picking an object in this command. Thank you so much for your help. Clark
13
2671
by: AliRezaGoogle | last post by:
Dear Members, I have a problem in the concepts of Monit.Enter and Monitor.Exit (Before everything I should say that I know how to solve this problem by using Monitor.Wait and I do not need a solution. But this question sticks to my head as a conceptual problem) Suppose there are two threads T1, T2 running concurrently:
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8523
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
8626
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...
1
6178
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
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2749
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.