#1 - Why are you trying to do this?  This doesn't look like it performs
anything useful.

#2 - It appears that Microsoft's implementation is more accepting than
the specifications for Monitor.Exit.  The docs are pretty clear.

-- arlie


-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Jeff Varszegi
Sent: Friday, October 17, 2003 10:59 AM
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] Synchronization question


I've written some code that runs fine on Windows, but when someone tried
to run it under Mono, it threw this exception:

Unhandled Exception: System.Threading.SynchronizationLockException: Not
locked by this thread

The code in question is pretty detailed, but the synchronization scheme
boils down to this: I have two overlapping (avoiding the word
"interlocked") synchronized regions, where I start, the first, start the
second, exit the first, then exit the second, like this:

object monitor1 = new object();
object monitor2 = new object();
lock (monitor1) {
   // ...
   lock (monitor2) {
      Monitor.Exit(monitor1);
      // ...
   }
}

I was thinking that this might be because the Mono implementation
requires that if you use the Monitor class to release a lock, you must
have used it to acquire the same lock (since it must be just holding a
handle to the current thread set when you called the Enter() method),
and Microsoft's .NET wasn't built that way.  This brings up the question
of whether this behavior is part of the platform specification.  Any
quick answers for this .NET newbie?

Thanks in advance,

Jeff

===================================
This list is hosted by DevelopMentorR  http://www.develop.com NEW!
ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to