Skip to content

libobs: os_sleep_ms(1) becomes Sleep(0) on Windows 8+, turning 1 ms retry loops into yield-spins #1274

Closed

Description

@zackees

Part of #1273. A (root cause).

os_sleep_ms subtracts 1 ms on Windows 8+ before calling Sleep, so os_sleep_ms(1) becomes Sleep(0). Sleep(0) only yields: on an idle machine a loop that "sleeps 1 ms" between retries spins at ~100% of one core.

  • C: libobs/util/platform-windows.c.h:365-371
  • Rust port (exported in place of the C one): rust/obs-util/src/platform/windows/host.rs:719-724
if (get_winver() >= 0x0602 && duration > 0)
	duration--;
Sleep(duration);

This is inherited from upstream OBS ("windows 8+ appears to have decreased sleep precision"). Callers that pass 1 are the spin sites in the sibling issues (Lua graphics lock, AMF input retry, AJA output thread).

Fix: never turn a positive duration into 0 (e.g. if (duration > 1) duration--;), in both the C and Rust versions, with the Tier 3 parity test updated to match. Optionally, use a high-resolution waitable timer for short sleeps.

Test: a Windows unit test showing that os_sleep_ms(1) in a loop runs well under ~1000 iterations per second (a yield-spin runs hundreds of thousands); plus Tier 1/3 coverage of the new rule.

Activity

  1. zackees commented on Oct 17, 2026

    @zackees
    MemberAuthor

    Claiming. Plan: never turn a positive duration into 0 (duration > 1 → duration--) in both libobs/util/platform-windows.c.h and rust/obs-util/src/platform/windows/host.rs, keeping the Rust port in parity with the C (or listing it as an intentional difference if the oracle is the pristine upstream C). RED: a Windows test that os_sleep_ms(1) in a loop stays well under ~1000 iterations per second, plus a Tier 1 test of the duration rule.

  2. added
    claimedAn agent or person has claimed this; check the claim comment before starting
    on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimedAn agent or person has claimed this; check the claim comment before starting

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions