Merge pull request #4828 from BrzVlad/fix-windows-ci
authorVlad Brezae <brezaevlad@gmail.com>
Fri, 12 May 2017 19:43:35 +0000 (22:43 +0300)
committerGitHub <noreply@github.com>
Fri, 12 May 2017 19:43:35 +0000 (22:43 +0300)
[runtime] Fix windows ci

mono/metadata/threads.c
mono/tests/thread-suspend-selfsuspended.cs
mono/tests/thread-suspend-suspended.cs

index 6ae7eaa0c72dcde34e6b49afac8aa7a7ce409048..5cc8e1d86f906d0541dff394a7f445f59fb8de8f 100644 (file)
@@ -4435,14 +4435,17 @@ mono_thread_execute_interruption (void)
        LOCK_THREAD (thread);
 
        /* MonoThread::interruption_requested can only be changed with atomics */
-       if (mono_thread_clear_interruption_requested (thread)) {
-               /* this will consume pending APC calls */
+       if (!mono_thread_clear_interruption_requested (thread)) {
+               UNLOCK_THREAD (thread);
+               return NULL;
+       }
+
+       /* this will consume pending APC calls */
 #ifdef HOST_WIN32
-               WaitForSingleObjectEx (GetCurrentThread(), 0, TRUE);
+       WaitForSingleObjectEx (GetCurrentThread(), 0, TRUE);
 #endif
-               /* Clear the interrupted flag of the thread so it can wait again */
-               mono_thread_info_clear_self_interrupt ();
-       }
+       /* Clear the interrupted flag of the thread so it can wait again */
+       mono_thread_info_clear_self_interrupt ();
 
        /* If there's a pending exception and an AbortRequested, the pending exception takes precedence */
        if (sys_thread->pending_exception) {
index c9681dffed266dd47043952cc88277f433298ecb..02a63a4bb39acc2047dfa40ac05bda0be3e442be 100644 (file)
@@ -7,12 +7,15 @@ class Driver
        public static void Main ()
        {
                bool finished = false;
+               int can_gc = 0;
 
                Thread t1 = Thread.CurrentThread;
 
                Thread t2 = new Thread (() => {
                        while (!finished) {
-                               GC.Collect ();
+                               int local_can_gc = can_gc;
+                               if (local_can_gc > 0 && Interlocked.CompareExchange (ref can_gc, local_can_gc - 1, local_can_gc) == local_can_gc)
+                                       GC.Collect ();
 
                                try {
                                        t1.Resume ();
@@ -27,7 +30,8 @@ class Driver
 
                Thread.Sleep (10);
 
-               for (int i = 0; i < 50 * 40 * 20; ++i) {
+               for (int i = 0; i < 50 * 40 * 5; ++i) {
+                       Interlocked.Increment (ref can_gc);
                        Thread.CurrentThread.Suspend ();
                        if ((i + 1) % (50) == 0)
                                Console.Write (".");
index 994042b22875b17b0ff6ca3413174a06a66b20ff..eb681653e600e200d97b7ebec44140c3c2a253d3 100644 (file)
@@ -8,6 +8,7 @@ class Driver
        public static void Main ()
        {
                bool finished = false;
+               int can_gc = 0;
 
                Thread t1 = new Thread (() => {
                        while (!finished) {}
@@ -15,7 +16,9 @@ class Driver
 
                Thread t2 = new Thread (() => {
                        while (!finished) {
-                               GC.Collect ();
+                               int local_can_gc = can_gc;
+                               if (local_can_gc > 0 && Interlocked.CompareExchange (ref can_gc, local_can_gc - 1, local_can_gc) == local_can_gc)
+                                       GC.Collect ();
                                Thread.Yield ();
                        }
                });
@@ -25,8 +28,9 @@ class Driver
 
                Thread.Sleep (10);
 
-               for (int i = 0; i < 50 * 40 * 20; ++i) {
+               for (int i = 0; i < 50 * 40 * 5; ++i) {
                        t1.Suspend ();
+                       Interlocked.Increment (ref can_gc);
                        Thread.Yield ();
                        t1.Resume ();
                        if ((i + 1) % (50) == 0)