[Mono-bugs] [Bug 62421][Nor] New - Multiple calls to System.Threading.Timer.Change( ) can cause unexpected multiple callbacks
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Wed, 4 Aug 2004 07:58:26 -0400 (EDT)
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 dev@6wardlaw.freeserve.co.uk.
http://bugzilla.ximian.com/show_bug.cgi?id=62421
--- shadow/62421 2004-08-04 07:58:26.000000000 -0400
+++ shadow/62421.tmp.23382 2004-08-04 07:58:26.000000000 -0400
@@ -0,0 +1,94 @@
+Bug#: 62421
+Product: Mono: Class Libraries
+Version: unspecified
+OS: Red Hat 9.0
+OS Details: Fedora Core 1
+Status: NEW
+Resolution:
+Severity: Unknown
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: dev@6wardlaw.freeserve.co.uk
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Multiple calls to System.Threading.Timer.Change( ) can cause unexpected multiple callbacks
+
+Description of Problem:
+
+Repeated changing of the timing settings of a System.Threading.Timer
+object can lead to unexpected multiple calls to the callback. This is due
+to the 'set_count' field of the underlying event not being cleared each
+time Change( ) is called. This results in the callback being called for
+each 'set_count'.
+
+
+Steps to reproduce the problem:
+1. Download the attached test case and compile ( I used 'Mono C# compiler
+version 1.0.0.0' )
+2. Run the compiled executable a number of times
+3. Check the output
+
+Actual Results:
+0Changing timer
+1Changing timer
+2Changing timer
+3Changing timer
+4Changing timer
+5Changing timer
+6Changing timer
+7Changing timer
+8Changing timer
+9Changing timer
+Timer callback called *******************************************
+Timer callback called *******************************************
+Timer callback called *******************************************
+Timer callback called *******************************************
+Timer callback called *******************************************
+Timer callback called *******************************************
+Timer callback called *******************************************
+Timer callback called *******************************************
+Timer callback called *******************************************
+Timer callback called *******************************************
+
+
+Expected Results:
+0Changing timer
+1Changing timer
+2Changing timer
+3Changing timer
+4Changing timer
+5Changing timer
+6Changing timer
+7Changing timer
+8Changing timer
+9Changing timer
+Timer callback called *******************************************
+
+
+How often does this happen?
+Almost every time - because of a race condition
+
+
+Additional Information:
+
+Suggest fix is to reset the auto-reset event before setting it.
+
+--- /tmp/mono-cvs/mcs/class/corlib/System.Threading/Timer.cs 2004-06-
+15 10:51:58.000000000 +0100
++++ /tmp/mono/mcs-1.0/class/corlib/System.Threading/Timer.cs 2004-08-
+04 12:45:18.000000000 +0100
+@@ -199,6 +199,7 @@
+ runner.DueTime = dueTime;
+ runner.Period = period;
+ runner.Abort ();
++ start_event.Reset( );
+ start_event.Set ();
+ return true;
+ }
+
+
+This will ensure that the 'set_count' field of the underlying event is
+cleared.