Commit b687d6a7 authored by Ian Lance Taylor's avatar Ian Lance Taylor

misc/cgo/testcarchive, misc/cgo/testcshared: sleep instead of sched_yield

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: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 1e917312
......@@ -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");
......
......@@ -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");
......
......@@ -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");
......
......@@ -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");
......
......@@ -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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment