diff --git a/src/generics/lib.generics.ts b/src/generics/lib.generics.ts index a46f453..2c91523 100644 --- a/src/generics/lib.generics.ts +++ b/src/generics/lib.generics.ts @@ -873,7 +873,7 @@ class ThreadHandle { // thread does too, so their counts change atomically from here on (erased under the // other models) Shared.share(this.start); - this.handle = tslang_thread_spawn(__thread_entry, this.start); + this.handle = tslang_thread_spawn(__thread_entry, this.start); } join(): R { diff --git a/src/native/lib.native.d.ts b/src/native/lib.native.d.ts index 8ec1a2d..75c1858 100644 --- a/src/native/lib.native.d.ts +++ b/src/native/lib.native.d.ts @@ -126,11 +126,10 @@ declare function GC_gcollect(): void; // thread @nodrops declare function std_this_thread_sleep_for(milliseconds: u32): void; -// Threads (wrappers/thread.cpp). `entry` is a function `(arg: Opaque) => u32` cast to an Opaque: a -// function-typed parameter of a declared function reaches C as a three-pointer struct, not a code -// pointer. The new thread calls back into TypeScript, but only into the ThreadStart `arg` names, -// which the Thread keeps until join: nothing the caller lends is dropped. -@nodrops declare function tslang_thread_spawn(entry: Opaque, arg: Opaque): Opaque; +// Threads (wrappers/thread.cpp). @cdecl: `entry` reaches C as a function pointer. The new thread calls +// back into TypeScript, but only into the ThreadStart `arg` names, which the Thread keeps until join: +// nothing the caller lends is dropped. +@cdecl @nodrops declare function tslang_thread_spawn(entry: (arg: Opaque) => u32, arg: Opaque): Opaque; @nodrops declare function tslang_thread_join(handle: Opaque): void; @nodrops declare function tslang_thread_hardware_concurrency(): u32; // Atomics.wait / notify: 0 "ok", 1 "not-equal", 2 "timed-out"; notify answers how many it woke diff --git a/src/wrappers/thread.cpp b/src/wrappers/thread.cpp index 8198709..fc89abc 100644 --- a/src/wrappers/thread.cpp +++ b/src/wrappers/thread.cpp @@ -69,9 +69,8 @@ struct CollectorRegistration typedef uint32_t (*ThreadEntry)(void *); -extern "C" TSLANG_EXPORT void *tslang_thread_spawn(void *entry, void *arg) +extern "C" TSLANG_EXPORT void *tslang_thread_spawn(ThreadEntry start, void *arg) { - auto start = reinterpret_cast(entry); return new std::thread([start, arg]() { #ifdef TSLANG_MM_GC CollectorRegistration registration;