|
13 | 13 | #endif |
14 | 14 |
|
15 | 15 | #include <stdalign.h> |
| 16 | +#include <assert.h> |
16 | 17 |
|
17 | 18 | static void dummy_0() |
18 | 19 | { |
@@ -558,13 +559,17 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att |
558 | 559 | __wait(&args->control, 0, 3, 0); |
559 | 560 | } |
560 | 561 | #else |
| 562 | +#define WASI_THREADS_MAX_TID 0x1FFFFFFF |
561 | 563 | /* `wasi_thread_spawn` will either return a host-provided thread ID (TID) |
562 | | - * (`>= 0`) or an error code (`< 0`). As in the unmodified version, all |
563 | | - * spawn failures translate to EAGAIN; unlike the modified version, there is |
564 | | - * no need to "start up" the child thread--the host does this. If the spawn |
565 | | - * did succeed, then we store the TID atomically, since this parent thread |
566 | | - * is racing with the child thread to set this field; this way, whichever |
567 | | - * thread reaches this point first can continue without waiting. */ |
| 564 | + * (`<1, 0x1FFFFFFF>`) or an error code (`< 0`). Please note that `0` is |
| 565 | + * reserved for compatibility reasons and must not be returned by the runtime. |
| 566 | + * As in the unmodified version, all spawn failures translate to EAGAIN; |
| 567 | + * unlike the modified version, there is no need to "start up" the child |
| 568 | + * thread--the host does this. If the spawn did succeed, then we store the |
| 569 | + * TID atomically, since this parent thread is racing with the child thread |
| 570 | + * to set this field; this way, whichever thread reaches this point first |
| 571 | + * can continue without waiting. */ |
| 572 | + assert(ret != 0 && ret <= WASI_THREADS_MAX_TID); |
568 | 573 | if (ret < 0) { |
569 | 574 | ret = -EAGAIN; |
570 | 575 | } else { |
|
0 commit comments