Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Wait until deadline variant

Open
#231 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
wasm

Research direction

No files or tests are named in the issue. Start by reading the dependency, #230, then review the proposal's discussion of Atomics.waitAsync and absolute versus relative waits across operating systems and embedded hardware. Done should be a specified deadline-based wait variant with clear semantics and its relationship to the existing duration-based form.

Written by the indexing model from the issue text.

Description

This obviously depends on #230.

Waiting for a duration is useful for simple blocking waits, but event loops generally find deadlines more convenient to work with, since you can just throw all the deadlines into a heap, sort by deadline, and (if your loop is multi-threaded) make your wait condition include timer add/remove events. Browser runtimes would already likely need a similar model anyways because of Atomics.waitAsync, but it's easy for a runtime using one model to expose the other.

Also, the type of wait differs heavily between platforms, with some accepting absolute deadlines, some accepting relative timeouts, and some accepting both:

  • Operating systems:
    • Linux: all futex waits other than FUTEX_WAIT use absolute deadlines, and even that one has an absolute alternative documented in its manpages.
    • Fuschia only uses absolute deadlines in its zx_futex_wait syscall, and offers no relative equivalent.
    • macOS provides both os_sync_wait_on_address_with_deadline and os_sync_wait_on_address_with_timeout.
    • OpenBSD and Windows only offer relative timeouts in their APIs.
    • pthread_condvar_timedwait only uses absolute timeouts.
  • Embedded hardware:
    • 32-bit ARM's SysTick is effectively timeout-based. It decrements every tick until it hits zero, in which it then triggers an interrupt. Setting the register essentially sets the number of ticks to wait before sending the interrupt.
    • RISC-V's privileged spec uses *timecmp registers corresponding to *time targets and triggers an interrupt whenever they're equal, effectively using a deadline-based system.
    • x86-64's HPET works nearly identically to RISC-V's mechanism. (This mostly only has relevance for VM-based server-side runtimes.)
    • The real-time clock specified by ACPI for motherboards uses deadlines. (This is sometimes used on high-end microcontrollers.)

Will note that it's easy to do one in terms of the other.

  • If all waits are absolute, relative waits are as simple as using a deadline of current_time() + timeout.
  • If all waits are relative, absolute waits are as simple as using a timeout of max(target_time - current_time(), 0).
Dominant language
WebAssembly
Stars
767
Forks
54
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from WebAssembly/threads

All issues in WebAssembly/threads

Similar issues

More Operating Systems issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.