]> Cypherpunks repositories - gostls13.git/commitdiff
misc/cgo/testcarchive, misc/cgo/testcshared: sleep instead of sched_yield
authorIan Lance Taylor <iant@golang.org>
Tue, 15 Nov 2016 00:50:15 +0000 (16:50 -0800)
committerIan Lance Taylor <iant@golang.org>
Tue, 15 Nov 2016 05:35:54 +0000 (05:35 +0000)
Apparently when GOMAXPROCS == 1 a simple sched_yield in a tight loop is
not necessarily sufficient to permit a signal handler to run. Instead,
sleep for 1/1000 of a second.

Fixes #16649.

Change-Id: I83910144228556e742b7a92a441732ef61aa49d9
Reviewed-on: https://go-review.googlesource.com/33239
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
misc/cgo/testcarchive/main2.c
misc/cgo/testcarchive/main3.c
misc/cgo/testcarchive/main4.c
misc/cgo/testcshared/main4.c
misc/cgo/testcshared/main5.c

index 56f890cad485f76a2af5a612a082f65278961c5c..ea3798612984e9abdbc2a8c8b0d24f19db36a50f 100644 (file)
@@ -112,6 +112,7 @@ int main(int argc, char** argv) {
        int verbose;
        sigset_t mask;
        int i;
+       struct timespec ts;
 
        verbose = argc > 1;
        setvbuf(stdout, NULL, _IONBF, 0);
@@ -161,9 +162,9 @@ int main(int argc, char** argv) {
        // Wait until the signal has been delivered.
        i = 0;
        while (!sigioSeen) {
-               if (sched_yield() < 0) {
-                       perror("sched_yield");
-               }
+               ts.tv_sec = 0;
+               ts.tv_nsec = 1000000;
+               nanosleep(&ts, NULL);
                i++;
                if (i > 100000) {
                        fprintf(stderr, "looping too long waiting for signal\n");
index 11046d087d7c968e641da0fd668770bd7cc53e3e..bb7eeda032b4b7476422ccaf4c67e4fa04acac41 100644 (file)
@@ -9,6 +9,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <sched.h>
 
 #include "libgo3.h"
@@ -28,6 +29,7 @@ int main(int argc, char** argv) {
        int verbose;
        struct sigaction sa;
        int i;
+       struct timespec ts;
 
        verbose = argc > 2;
        setvbuf(stdout, NULL, _IONBF, 0);
@@ -64,9 +66,9 @@ int main(int argc, char** argv) {
        // Wait until the signal has been delivered.
        i = 0;
        while (!sigioSeen) {
-               if (sched_yield() < 0) {
-                       perror("sched_yield");
-               }
+               ts.tv_sec = 0;
+               ts.tv_nsec = 1000000;
+               nanosleep(&ts, NULL);
                i++;
                if (i > 100000) {
                        fprintf(stderr, "looping too long waiting for signal\n");
@@ -138,9 +140,9 @@ int main(int argc, char** argv) {
        // Wait until the signal has been delivered.
        i = 0;
        while (!sigioSeen) {
-               if (sched_yield() < 0) {
-                       perror("sched_yield");
-               }
+               ts.tv_sec = 0;
+               ts.tv_nsec = 1000000;
+               nanosleep(&ts, NULL);
                i++;
                if (i > 100000) {
                        fprintf(stderr, "looping too long waiting for signal\n");
index 353f980c50d47e3336ff66ebc0770ff3b210487c..39f7c309df58c0dec02e30e10f610369bb10b759 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <sched.h>
 #include <pthread.h>
 
@@ -48,6 +49,7 @@ static void* thread1(void* arg __attribute__ ((unused))) {
        stack_t ss;
        int i;
        stack_t nss;
+       struct timespec ts;
 
        // Set up an alternate signal stack for this thread.
        memset(&ss, 0, sizeof ss);
@@ -73,9 +75,9 @@ static void* thread1(void* arg __attribute__ ((unused))) {
        // Wait until the signal has been delivered.
        i = 0;
        while (SIGIOCount() == 0) {
-               if (sched_yield() < 0) {
-                       perror("sched_yield");
-               }
+               ts.tv_sec = 0;
+               ts.tv_nsec = 1000000;
+               nanosleep(&ts, NULL);
                i++;
                if (i > 100000) {
                        fprintf(stderr, "looping too long waiting for signal\n");
@@ -105,6 +107,7 @@ static void* thread2(void* arg __attribute__ ((unused))) {
        int i;
        int oldcount;
        pthread_t tid;
+       struct timespec ts;
        stack_t nss;
 
        // Set up an alternate signal stack for this thread.
@@ -129,9 +132,9 @@ static void* thread2(void* arg __attribute__ ((unused))) {
        // Wait until the signal has been delivered.
        i = 0;
        while (SIGIOCount() == oldcount) {
-               if (sched_yield() < 0) {
-                       perror("sched_yield");
-               }
+               ts.tv_sec = 0;
+               ts.tv_nsec = 1000000;
+               nanosleep(&ts, NULL);
                i++;
                if (i > 100000) {
                        fprintf(stderr, "looping too long waiting for signal\n");
index fd7b5b31ed13948131d42307b8f531fa73048b76..ffc4ecabad164698a5db0aaa47b696d780fc7e7f 100644 (file)
@@ -77,6 +77,7 @@ int main(int argc, char** argv) {
        void (*fn)(void);
        sigset_t mask;
        int i;
+       struct timespec ts;
 
        verbose = argc > 2;
        setvbuf(stdout, NULL, _IONBF, 0);
@@ -166,9 +167,9 @@ int main(int argc, char** argv) {
        // Wait until the signal has been delivered.
        i = 0;
        while (!sigioSeen) {
-               if (sched_yield() < 0) {
-                       perror("sched_yield");
-               }
+               ts.tv_sec = 0;
+               ts.tv_nsec = 1000000;
+               nanosleep(&ts, NULL);
                i++;
                if (i > 100000) {
                        fprintf(stderr, "looping too long waiting for signal\n");
index 97a258f21a639996e6ed5f8ed142984f385729ed..57c64a122eff1a3f75940d9bbebcc77f6a138548 100644 (file)
@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <sched.h>
 #include <dlfcn.h>
 
@@ -31,6 +32,7 @@ int main(int argc, char** argv) {
        void (*fn1)(void);
        int (*sawSIGIO)(void);
        int i;
+       struct timespec ts;
 
        verbose = argc > 2;
        setvbuf(stdout, NULL, _IONBF, 0);
@@ -77,9 +79,9 @@ int main(int argc, char** argv) {
        // Wait until the signal has been delivered.
        i = 0;
        while (!sigioSeen) {
-               if (sched_yield() < 0) {
-                       perror("sched_yield");
-               }
+               ts.tv_sec = 0;
+               ts.tv_nsec = 1000000;
+               nanosleep(&ts, NULL);
                i++;
                if (i > 100000) {
                        fprintf(stderr, "looping too long waiting for signal\n");
@@ -182,9 +184,9 @@ int main(int argc, char** argv) {
        // Wait until the signal has been delivered.
        i = 0;
        while (!sigioSeen) {
-               if (sched_yield() < 0) {
-                       perror("sched_yield");
-               }
+               ts.tv_sec = 0;
+               ts.tv_nsec = 1000000;
+               nanosleep(&ts, NULL);
                i++;
                if (i > 100000) {
                        fprintf(stderr, "looping too long waiting for signal\n");