Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Jordan <robertj@gmx.net>2006-12-11 23:11:41 +0300
committerRobert Jordan <robertj@gmx.net>2006-12-11 23:11:41 +0300
commit2d16546be98efed43e436790273cf4dde736cbaf (patch)
treeea469cef32c3479019bf6791e2a3aa2cacbd6f7d /mcs/class/System/System.Timers
parente08935de49f8845f941f646888d2e1a30f41fa72 (diff)
2006-03-19 Robert Jordan <robertj@gmx.net>
* Timer.cs: Fix race condition of the wait handle object. Fixes bug #77847. svn path=/trunk/mcs/; revision=69357
Diffstat (limited to 'mcs/class/System/System.Timers')
-rw-r--r--mcs/class/System/System.Timers/ChangeLog5
-rw-r--r--mcs/class/System/System.Timers/Timer.cs30
2 files changed, 25 insertions, 10 deletions
diff --git a/mcs/class/System/System.Timers/ChangeLog b/mcs/class/System/System.Timers/ChangeLog
index 0569399c8f2..1062da725c2 100644
--- a/mcs/class/System/System.Timers/ChangeLog
+++ b/mcs/class/System/System.Timers/ChangeLog
@@ -1,3 +1,8 @@
+2006-03-19 Robert Jordan <robertj@gmx.net>
+
+ * Timer.cs: Fix race condition of the wait handle object.
+ Fixes bug #77847.
+
2005-11-16 Sebastien Pouliot <sebastien@ximian.com>
* TimersDescriptionAttribute.cs: Revert Description property fix
diff --git a/mcs/class/System/System.Timers/Timer.cs b/mcs/class/System/System.Timers/Timer.cs
index dc07110bd61..075bcdb2003 100644
--- a/mcs/class/System/System.Timers/Timer.cs
+++ b/mcs/class/System/System.Timers/Timer.cs
@@ -44,6 +44,8 @@ namespace System.Timers
double interval;
ISynchronizeInvoke so;
ManualResetEvent wait;
+ Thread thread;
+ object locker = new object ();
[Category("Behavior")]
[TimersDescription("Occurs when the Interval has elapsed.")]
@@ -84,9 +86,10 @@ namespace System.Timers
enabled = value;
if (value) {
- Thread t = new Thread (new ThreadStart (StartTimer));
- t.IsBackground = true;
- t.Start ();
+ wait = new ManualResetEvent (false);
+ thread = new Thread (new ThreadStart (StartTimer));
+ thread.IsBackground = true;
+ thread.Start ();
} else {
StopTimer ();
}
@@ -175,8 +178,6 @@ namespace System.Timers
void StartTimer ()
{
- wait = new ManualResetEvent (false);
-
WaitCallback wc = new WaitCallback (Callback);
while (enabled && wait.WaitOne ((int) interval, false) == false) {
if (autoReset == false)
@@ -184,16 +185,25 @@ namespace System.Timers
ThreadPool.QueueUserWorkItem (wc, this);
}
-
+
wc = null;
- ((IDisposable) wait).Dispose ();
- wait = null;
+
+ lock (locker) {
+ ((IDisposable) wait).Dispose ();
+ wait = null;
+ }
}
void StopTimer ()
{
- if (wait != null)
- wait.Set ();
+ lock (locker) {
+ if (wait != null)
+ wait.Set ();
+ }
+
+ // the sleep speeds up the join under linux
+ Thread.Sleep (0);
+ thread.Join ();
}
}
}