Skip to content

Don't assert on a timer started during dispatch - #24

Open
nob13 wants to merge 1 commit into
any1:masterfrom
nob13:nob/timer0
Open

Don't assert on a timer started during dispatch#24
nob13 wants to merge 1 commit into
any1:masterfrom
nob13:nob/timer0

Conversation

@nob13

@nob13 nob13 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

aml_dispatch() reads now once, drains what is due, then asserts the earliest
remaining deadline is strictly in the future:

uint64_t now = aml__gettime_us(self);
while (aml__handle_timeout(self, now));

struct aml_timer* earliest = aml__get_timer_with_earliest_deadline(self);
if (earliest) {
        assert(earliest->deadline > now);

aml_start_timer() may run on another thread in between, and computes its
deadline from a later aml__gettime_us(). So the invariant is >= now, not
> now. A zero timeout collides within the same microsecond and hits it easily.

Repro: 2000 zero-timeout timers from a foreign thread against a busy loop aborts
3 of 5 runs before, 0 of 5 after.

Such a timer gets its deadline after now was read, so it can be equal.
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