Skip to content

Remove TODO from libpthread.js. NFC - #26603

Merged
sbc100 merged 2 commits into
emscripten-core:mainfrom
sbc100:remove_todo
Apr 1, 2026
Merged

sbc100 merged 2 commits into
emscripten-core:mainfrom
sbc100:remove_todo

Conversation

@sbc100

@sbc100 sbc100 commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator

This TODO was added in #18861 when the following line read:

Atomics.waitAsync(HEAP32, pthread_ptr >> 2, pthread_ptr);

I'm not sure if the TODO here was refering to that 2nd or 3rd argument but they both work fine under wasm64 right now.

The second argument now uses getHeapOffset('pthread_ptr', 'i32') which works find under wasm64 even for addresses over 4gb.

The third argument here is actually not important since its value never changes, it just needs to match the contents of the memory at the specific location. I verified that this works in wasm64_4gb mode. The pthread_ptr is simply converted to a U32 and then compared to the low bits of the 64-bit pthread_ptr in memory. The assert on the line below ensure that this does indeed work. If it didn't then "not-equal" would be returned from Atomics.waitAsync

@sbc100
sbc100 requested a review from tlively April 1, 2026 22:45
This TODO was added in emscripten-core#18861 when the following line read:

```
Atomics.waitAsync(HEAP32, pthread_ptr >> 2, pthread_ptr);
```

I'm not sure if the TODO here was refering to that 2nd or 3rd argument
but they both work fine under wasm64 right now.

The second argument now uses `getHeapOffset('pthread_ptr', 'i32')` which
works find under wasm64 even for addresses over 4gb.

The third argument here is actually not important since its value never
changes, it just needs to match the contents of the memory at the
specific location.  I verified that this works in wasm64_4gb mode.  The
`pthread_ptr` is simply converted to a U32 and then compared to the
low bits of the 64-bit pthread_ptr in memory.  The assert on the line
below ensure that this does indeed work.  If it didn't then
`"not-equal"` would be returned from `Atomics.waitAsync`
Comment thread src/lib/libpthread.js Outdated
Co-authored-by: Thomas Lively <tlively123@gmail.com>
@sbc100
sbc100 merged commit 503e0ad into emscripten-core:main Apr 1, 2026
4 of 18 checks passed
@sbc100
sbc100 deleted the remove_todo branch April 1, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants