/
nv-lang
/
nova
Обзор
Документация
Войти
/
nv-lang
/
nova
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
spec_tests/conformance/onceguard_commit_path.nv
59 строк
2 KB
Evgeniy Golovin
fix(std/sync): W_TRY_WITHOUT_SIBLING — снять try_-префикс на 8 sync-методах
17 июл 2026, 12:35
17 июл 2026, 12:35
b7b7e1a
Код
Авторство
О чём код?
// Plan 103.9 (D174) — Positive: OnceGuard commit path. // // Once.start_won() + Once.make_guard() → OnceGuard consume. // Winning fiber receives guard; guard.commit() → Once → DONE. // Subsequent callers: start_won() returns false (Once already DONE). module spec_tests.conformance test "start_won returns true for first caller, false after commit" { mut once = Once.new() mut body_ran = AtomicInt.new(0) if once.start_won() { consume g = once.make_guard() body_ran.fetch_add(1) g.commit() } assert(body_ran.load() == 1) assert(once.is_completed() == true) // Second call: start_won returns false (already DONE) if once.start_won() { assert(false) // should not execute — already done // (This branch is unreachable — prevent consume error:) consume g2 = once.make_guard() g2.commit() } // Reaching here without entering second if means start_won returned false // which is expected. } test "OnceGuard commit makes once.is_completed() == true" { mut once = Once.new() assert(once.is_completed() == false) if once.start_won() { consume g = once.make_guard() g.commit() } assert(once.is_completed() == true) } test "make_guard + commit: single-fiber ownership" { mut once = Once.new() mut ran = AtomicInt.new(0) // run() returns true exactly once ro won = once.start_won() assert(won == true) // Create guard and commit consume g = once.make_guard() ran.fetch_add(1) g.commit() assert(ran.load() == 1) assert(once.is_completed() == true) }