Skip to content

Correct result type#18

Merged
iv461 merged 6 commits into
mainfrom
fix/result_mt
Feb 18, 2026
Merged

Correct result type#18
iv461 merged 6 commits into
mainfrom
fix/result_mt

Conversation

@iv461

@iv461 iv461 commented Feb 18, 2026

Copy link
Copy Markdown
Owner

Fixes the result type: It has two states, not three (I had managed to somehow confuse it with the promise state, now both concepts are separate).

Also makes the async/await API thread-safe:

  • A race between promise resolution and rejection may occur when calling services since the timer task and the service response task may be scheduled into separate executor threads. They are now synchronized by an atomic exchange that says whether the promise was resolved/rejected yet. If the promise was already resolved/rejected, subsequent resolutions/rejections are ignored. This is lock-free and therefore the fastest way to prevent this race.
  • TF callbacks are synchronized with a mutex. This makes it slower because a hashtable has to be copied now.

Ivo Ivanov added 6 commits February 18, 2026 15:29
…ng an atomic bool. This is because we do not need pthread once: pthread once blocks other threads until the initialization is finished, but we do not need that, and atomics are faster than pthread once. A thread only needs to know if another thread won the race of resolving the promise.
@iv461 iv461 merged commit 8532979 into main Feb 18, 2026
3 checks passed
@iv461 iv461 deleted the fix/result_mt branch February 18, 2026 16:29
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.

1 participant