473,320 Members | 1,867 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.

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.Object );
Monitor::Enter( resource2.Object );
bool bMonitor1IsActive = true;

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

Monitor::Exit( resource1.Object );
bMonitor1IsActive = false;

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

Nov 10 '06 #1
2 1748
"Ian" <Ia*******@yahXX.comwrote in message
news:qk********************@weber.videotron.net...
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
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
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...
8
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...
6
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. ...
13
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...
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
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.