Skip to content

Timer facilities should have a sleep_until method #10324

Closed
@mstewartgallus

Description

@mstewartgallus

A sleep_until method for periodic timing without drifting is needed. In many cases this is much better to use than the sleep function. The Ada Ravenscar profile even forbids the use of the delay facility because it is so less predictable, and often leads to broken code. Currently, there is a periodic method one can use but for more complicated cases one would still need the sleep_until function.

Sample usage of the hypothetical sleep_until:

fn periodic(t : Timer) {
     let mut next_tick = time::precise_time_ns() / 100_000;
     loop {
          // .... Tick code

          next_tick += 100;
          timer.sleep_until(next_tick);
     }
}

Wikipedia example of delay causing clock drift http://en.wikibooks.org/wiki/Ada_Style_Guide/Concurrency#Delay_Statements

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions