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 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