Story Details

  • The missing cross-platform OS API for timers

    Posted: 2025-02-03 06:07:10

    The blog post argues for a standardized, cross-platform OS API specifically designed for timers. Existing timer mechanisms, like POSIX's timerfd and Windows' CreateWaitableTimer, while useful, differ significantly across operating systems, complicating cross-platform development. The author proposes a new API with a consistent interface that abstracts away these platform-specific details. This ideal API would allow developers to create, arm, and disarm timers, specifying absolute or relative deadlines with optional periodic behavior, all while handling potential issues like early wake-ups gracefully. This would simplify codebases and improve portability for applications relying on precise timing across different operating systems.

    Summary of Comments ( 18 )
    https://news.ycombinator.com/item?id=42915437

    The Hacker News comments discuss the complexities of cross-platform timer APIs, largely agreeing with the article's premise. Several commenters highlight the difficulties introduced by different operating systems' power management features, impacting timer accuracy and reliability. Specific challenges like signal coalescing and the lack of a unified interface for monotonic timers are mentioned. Some propose workarounds like busy-waiting for short durations or using platform-specific code for optimal performance. The need for a standardized API is reiterated, with suggestions for what such an API should offer, including considerations for power efficiency and different timer resolutions. One commenter points to the challenges of abstracting away hardware differences completely, suggesting the ideal solution may involve a combination of OS-level improvements and application-specific strategies.