src/runtime/cgo/gcc_libinit_windows.c | 20 ++++++++++++++++---- diff --git a/src/runtime/cgo/gcc_libinit_windows.c b/src/runtime/cgo/gcc_libinit_windows.c index a9b94c37139b446cb5d506c18f8d249d7a1ec122..2b5896bb221c6c1cade68ec1b6b13dbc56e5ee53 100644 --- a/src/runtime/cgo/gcc_libinit_windows.c +++ b/src/runtime/cgo/gcc_libinit_windows.c @@ -129,11 +129,23 @@ return ret; } void _cgo_beginthread(void (*func)(void*), void* arg) { + int tries; uintptr_t thandle; - thandle = _beginthread(func, 0, arg); - if (thandle == -1) { - fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno); - abort(); + for (tries = 0; tries < 20; tries++) { + thandle = _beginthread(func, 0, arg); + if (thandle == -1 && errno == EACCES) { + // "Insufficient resources", try again in a bit. + // + // Note that the first Sleep(0) is a yield. + Sleep(tries); // milliseconds + continue; + } else if (thandle == -1) { + break; + } + return; // Success! } + + fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno); + abort(); }