[Mono-bugs] [Bug 49824][Nor] New -
Threading.SyncronizationException thrown on calling
Monitor.Exit on an object that has not been locked.
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Fri Jun 24 01:52:14 EDT 2005
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by bmaurer at users.sf.net.
http://bugzilla.ximian.com/show_bug.cgi?id=49824
--- shadow/49824 2005-06-24 01:52:14.000000000 -0400
+++ shadow/49824.tmp.19948 2005-06-24 01:52:14.000000000 -0400
@@ -0,0 +1,133 @@
+Bug#: 49824
+Product: Mono: Runtime
+Version: unspecified
+OS: Red Hat 9.0
+OS Details: Standard Install
+Status: NEW
+Resolution:
+Severity: Unknown
+Priority: Normal
+Component: misc
+AssignedTo: bmaurer at users.sf.net
+ReportedBy: gileslforster at yahoo.co.uk
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Threading.SyncronizationException thrown on calling Monitor.Exit on an object that has not been locked.
+
+Please fill in this template when reporting a bug, unless you know what
+you are doing.
+Description of Problem:
+
+Steps to reproduce the problem:
+
+Bellow a simple console application calling Monitor.Exit(obj) on an
+object to which Monitor.Enter(obj) has not been called.
+
+using System;
+using System.Threading;
+
+namespace ConsoleApplication
+{
+ class Class1
+ {
+ [STAThread]
+ static void Main(string[] args)
+ {
+ Class1 x = new Class1();
+
+ Monitor.Exit(x);
+
+ Console.WriteLine("All done.");
+ }
+ }
+}
+
+Actual Results:
+
+[giles at Linux-02 Mono]$ mono ConsoleApplication.exe
+
+
+
+Unhandled Exception: System.Threading.SynchronizationLockException: Not
+locked
+
+in (unmanaged) /usr/lib/libmono.so.0(mono_raise_exception+0x20)
+[0x400aa8e9]
+
+in (unmanaged) /usr/lib/libmono.so.0(mono_monitor_exit+0x3b) [0x400c387d]
+
+in (unmanaged) /usr/lib/libmono.so.0 [0x400c3939]
+
+in <0x0003b> System.Threading.Monitor:Exit (object)
+
+in <0x00036> ConsoleApplication.Class1:Main (string[])
+
+
+Expected Results:
+
+[giles at Linux-02 Mono]$ mono ConsoleApplication.exe
+All done.
+[giles at Linux-02 Mono]$
+
+
+How often does this happen?
+
+Always.
+
+Additional Information:
+
+Under .NET 1.1 on Windows the default behaviour is to ignore the fact
+that Enter() has not been called if calling Exit() on an unlocked object
+for the current thread. On Mono it throws a SynchronizationLockException,
+leading to incompatible code. Not sure what the ECMA standard says but
+don't know where to look.
+
+Thanks,
+
+Giles
+
+------- Additional Comments From dick at ximian.com 2003-10-20 11:12 -------
+Looks like the ms Monitor implementation is rather buggy.
+
+using System;
+using System.Threading;
+
+namespace ConsoleApplication
+{
+ class Class1
+ {
+ static Class1 x;
+
+ static void OtherThread()
+ {
+ Monitor.Exit(x);
+ Console.WriteLine("Passed x Exit");
+ }
+
+ [STAThread]
+ static void Main(string[] args)
+ {
+ x = new Class1();
+ Monitor.Enter(x);
+ Thread thr=new Thread(new
+ThreadStart(Class1.OtherThread));
+ thr.Start();
+ thr.Join();
+
+ Console.WriteLine("All done.");
+ }
+ }
+}
+
+prints both WriteLines for me, ms runtime 1.1.
+
+Reading the Monitor class documentation again, I suppose it could be
+argued that "The current thread does not own the lock for the
+specified object" could be read so as to not throw
+SynchronizationLockException when the object is not locked at all, but
+unless my test above is faulty, it isn't thrown even when another
+thread _does_ own the lock. (Changing the Monitor.Exit(x) into a
+Monitor.Enter(x) does deadlock as expected though.)
+
More information about the mono-bugs
mailing list