Skip to content

Commit fe138a6

Browse files
committed
Return ENOTSUP from pthread_create when threads are not available.
See WebAssembly/wasi-libc#716
1 parent 7d3523f commit fe138a6

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

system/lib/pthread/library_pthread_stub.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ int pthread_barrier_destroy(pthread_barrier_t* mutex) { return 0; }
9292
int pthread_barrier_wait(pthread_barrier_t* mutex) { return 0; }
9393

9494
int __pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) {
95-
return EAGAIN;
95+
// ENOTSUP, while not mentioned in the pthread_create docs, does better
96+
// describe the situation.
97+
// See https://github.com/WebAssembly/wasi-libc/pull/716 for discussion
98+
// on this error code vs, for example, EAGAIN.
99+
return ENOTSUP;
96100
}
97101

98102
weak_alias(__pthread_create, emscripten_builtin_pthread_create);

test/other/test_pthread_stub.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ void* start_pthread(void* arg) {
2222
}
2323

2424
#define CHECK(X, EXPECTED) rtn = X; if (rtn != EXPECTED) printf(#X " returned %s\n", strerror(rtn)); assert(rtn == EXPECTED)
25-
#define CHECK_FAIL(X) CHECK(X, EAGAIN)
25+
#define CHECK_FAIL(X) CHECK(X, ENOTSUP)
2626
#define CHECK_SUCCESS(X) CHECK(X, 0)
2727

2828
#define CHECK_C11(X, expected) rtn = X; if (rtn != expected) printf(#X " returned %d\n", rtn); assert(rtn == expected)
2929
#define CHECK_C11_SUCCESS(X) CHECK_C11(X, thrd_success)
30-
#define CHECK_C11_FAIL(X) CHECK_C11(X, thrd_nomem)
30+
#define CHECK_C11_FAIL(X) CHECK_C11(X, thrd_error)
3131

3232
void test_c11_threads() {
3333
printf("test_c11_threads\n");

0 commit comments

Comments
 (0)