2009-04-15 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / tests / thread6.cs
index 0d25eff412d10083807a782c406a67056b62fb27..d1b6d81baff95692067048fcb5f93975f484634a 100644 (file)
@@ -4,6 +4,7 @@ using System.Threading;
 public class MultiThreadExceptionTest {
 
        public static int result = 0;
+       public static object started = new object ();
        
        public static void ThreadStart1 () {
                Console.WriteLine("{0} started", 
@@ -12,6 +13,9 @@ public class MultiThreadExceptionTest {
                try {
                        try {
                                try {
+                                       lock (started) {
+                                               Monitor.Pulse (started);
+                                       }
                                        int i = 0;
                                        try {
                                                while (true) {
@@ -87,7 +91,6 @@ public class MultiThreadExceptionTest {
        }
        
        public static int Main() {
-
                // Check aborting the current thread
                bool aborted = false;
                try {
@@ -100,22 +103,30 @@ public class MultiThreadExceptionTest {
                if (!aborted)
                        return 2;
 
-               Thread t1 = new Thread(new ThreadStart
-                       (MultiThreadExceptionTest.ThreadStart1));
-               t1.Name = "Thread 1";
+               Thread t1 = null;
 
-               Thread.Sleep (100);
-               
-               t1.Start();
+               lock (started) {
+                       t1 = new Thread(new ThreadStart
+                                                       (MultiThreadExceptionTest.ThreadStart1));
+                       t1.Name = "Thread 1";
+
+                       Thread.Sleep (100);
                
-               Thread.Sleep (200);
+                       t1.Start();
+
+                       Monitor.Wait (started);
+               }
+
+               Thread.Sleep (100);
+
                t1.Abort ("STATETEST");
 
                t1.Join ();
-               Console.WriteLine ("Result: " + result);
 
-               if (result != 59)
+               if (result != 59) {
+                       Console.WriteLine ("Result: " + result);
                        return 1;
+               }
 
                // Test from #68552
                try {