You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
obs-scripting: Lua graphics lock retry yield-spins on the graphics thread with no deadline #1275
shared/obs-scripting/obs-scripting-lua-source.c.h:193-197, on the graphics thread:
while (pthread_mutex_trylock(mutex) !=0) {
if (os_atomic_load_long(&lua_graphics_waiters) >0)
return false;
os_sleep_ms(1);
}
It has no time limit; it only exits once the lock is free or another graphics waiter appears. On Windows os_sleep_ms(1) is Sleep(0) (#1274), so while a Lua script holds its mutex the graphics thread yield-spins, on the same thread that renders every frame.
Fix: a real wait: a bounded pthread_mutex_timedlock-style wait, or an event or condvar signalled on unlock, with a deadline. Keep the existing "another waiter" escape.
Test: hold the mutex from another thread and count loop iterations, or the CPU time used by the waiting thread, over 100 ms; it must stay bounded.
Characterize the current lock_in_graphics behavior, including uncontended acquisition, the non-graphics path, retries under contention, and the graphics-waiter escape.
Add deterministic coverage against the production C function and run it on macOS; record the scope and validation limits.
This session is scoped to characterization only, before a separate RED regression and fix. ETA: characterization commit and evidence this session; no fix PR promised in this phase. Windows-specific Sleep(0) CPU behavior will remain unverified here.
Characterization completed locally at 265886747 on branch test/1275-lua-graphics-lock-characterization, based on master 7a56d867e. No production changes; no fix or RED regression yet.
Eight cmocka cases compile the actual private C helper via a configure-time slice, with controlled context, mutex, atomic-read and sleep dependencies. They cover the blocking path, immediate acquisition (even with a waiter), contention retries, existing/new waiter escape, acquisition before the waiter check, 10,000 failed attempts with fixed 1 ms sleep requests, and retries on non-EBUSY errors. The last two are characterized, not endorsed.
macOS validation: AppleClang 21, cmocka 2.0.2, -Wall -Wextra -Werror; all eight pass, and CTest passes 100 consecutive runs. Changing the generated waiter threshold from > 0 to > 1 fails both escape cases; restoring production passes. Pinned clang-format 22.1.3 and gersemi 0.25.0 checks pass.
The new tests.d fragment was built through a minimal standalone CMake driver. Full OBS build and OFF/ON Tier 2 were not run. These tests characterize control flow and requested sleeps, not real Lua/rendering, native thread scheduling, elapsed wait time, or Windows CPU usage. The branch is local and not pushed. Stopping at the requested characterization checkpoint.
Continuing the claim with RED → GREEN after characterization PR #1496 (queued).
Decisions: use a single nonblocking try-lock while holding the graphics context. The existing callers already return cached dimensions or skip rendering on a failed lock. This avoids polling and scheduler-dependent waits altogether; the non-graphics path keeps blocking acquisition. A contended Lua source may skip a frame until its lock is available, rather than stalling every source. Preserve the old characterization against a frozen original helper, and add separate production regression tests. ETA: RED draft PR and GREEN implementation this session.
Triage: concrete fix and test plan, claimed by @nathan-v with the characterization PR (#1496) first and a decision recorded (a single nonblocking try-lock while holding the graphics context, relying on the callers' existing cached-dimensions/skip-render path). Acceptance: no polling loop on the graphics thread, and the existing "another waiter" escape and cached-dimension behaviour covered by the RED → GREEN test. P2 (it can stall the render thread), size:S.
Correction to my triage above: this is already fixed. #1498 (merged 2026-10-20, after the characterization in #1496) replaced the retry loop with a single nonblocking try-lock (shared/obs-scripting/obs-scripting-lua-source.c.h:189 on master: return pthread_mutex_trylock(mutex) == 0;), so the graphics thread no longer spins. Thanks @nathan-v.
Activity
nathan-v commentedon Oct 20, 2026
Claiming: #1275 Lua graphics-lock wait characterization.
lock_in_graphicsbehavior, including uncontended acquisition, the non-graphics path, retries under contention, and the graphics-waiter escape.This session is scoped to characterization only, before a separate RED regression and fix. ETA: characterization commit and evidence this session; no fix PR promised in this phase. Windows-specific
Sleep(0)CPU behavior will remain unverified here.nathan-v commentedon Oct 20, 2026
Characterization completed locally at
265886747on branchtest/1275-lua-graphics-lock-characterization, based on master7a56d867e. No production changes; no fix or RED regression yet.Eight cmocka cases compile the actual private C helper via a configure-time slice, with controlled context, mutex, atomic-read and sleep dependencies. They cover the blocking path, immediate acquisition (even with a waiter), contention retries, existing/new waiter escape, acquisition before the waiter check, 10,000 failed attempts with fixed 1 ms sleep requests, and retries on non-EBUSY errors. The last two are characterized, not endorsed.
macOS validation: AppleClang 21, cmocka 2.0.2,
-Wall -Wextra -Werror; all eight pass, and CTest passes 100 consecutive runs. Changing the generated waiter threshold from> 0to> 1fails both escape cases; restoring production passes. Pinned clang-format 22.1.3 and gersemi 0.25.0 checks pass.The new
tests.dfragment was built through a minimal standalone CMake driver. Full OBS build and OFF/ON Tier 2 were not run. These tests characterize control flow and requested sleeps, not real Lua/rendering, native thread scheduling, elapsed wait time, or Windows CPU usage. The branch is local and not pushed. Stopping at the requested characterization checkpoint.nathan-v commentedon Oct 20, 2026
Continuing the claim with RED → GREEN after characterization PR #1496 (queued).
Decisions: use a single nonblocking try-lock while holding the graphics context. The existing callers already return cached dimensions or skip rendering on a failed lock. This avoids polling and scheduler-dependent waits altogether; the non-graphics path keeps blocking acquisition. A contended Lua source may skip a frame until its lock is available, rather than stalling every source. Preserve the old characterization against a frozen original helper, and add separate production regression tests. ETA: RED draft PR and GREEN implementation this session.
obs-scripting: Skip contended graphics locks
test: Characterize Lua graphics lock waits (obs-rust#1496)
test: Require nonblocking Lua graphics locks
obs-scripting: Skip contended graphics locks
obs-scripting: Avoid waiting on busy Lua graphics locks (obs-rust#1498)
zackees commentedon Oct 25, 2026
/ready
Triage: concrete fix and test plan, claimed by @nathan-v with the characterization PR (#1496) first and a decision recorded (a single nonblocking try-lock while holding the graphics context, relying on the callers' existing cached-dimensions/skip-render path). Acceptance: no polling loop on the graphics thread, and the existing "another waiter" escape and cached-dimension behaviour covered by the RED → GREEN test. P2 (it can stall the render thread), size:S.
zackees commentedon Oct 25, 2026
Correction to my triage above: this is already fixed. #1498 (merged 2026-10-20, after the characterization in #1496) replaced the retry loop with a single nonblocking try-lock (
shared/obs-scripting/obs-scripting-lua-source.c.h:189on master:return pthread_mutex_trylock(mutex) == 0;), so the graphics thread no longer spins. Thanks @nathan-v.