OxL Справочник OxL
РусскийEnglish

fn oxl_atomically

The runner of atomic { body } (§8.9, D-7521; the compiler lowers the block to this call): runs body as a transaction over the TVars (std.stm), again after a conflict or a failed check. The value is the one of the run that committed.

Example:

oxl✓ проверяется в CI
use std.stm { TVar }

fn main() io {
  let balance = TVar<i64>.new(10)
  atomic {
    balance.set(balance.get() + 5)
  }
  print("{atomic { balance.get() }}")
}
Вывод
15
pub(api) fn oxl_atomically<R>(body: fn() -> R) -> R

Потокобезопасность. transactions of different tasks are isolated; `body` may run more than once.

С версии. 1.0.0-beta

Параметры

ИмяТип
bodyfn() -> R

Возвращает

R

Эффекты

не объявлены (чистая, пока тело не говорит иное)

Определено в: std/core/task.oxl:256

См. также