JezK
Edit File: atomically-i.ri
U:RDoc::AnyMethod[iI"atomically:EFI"Concurrent#atomically;FF:privateo:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"ORun a block that reads and writes `TVar`s as a single atomic transaction. ;TI"PWith respect to the value of `TVar` objects, the transaction is atomic, in ;TI"Kthat it either happens or it does not, consistent, in that the `TVar` ;TI"Oobjects involved will never enter an illegal state, and isolated, in that ;TI"Ktransactions never interfere with each other. You may recognise these ;TI"+properties from database transactions.;To:RDoc::Markup::BlankLine o; ; [I"SThere are some very important and unusual semantics that you must be aware of:;T@o:RDoc::Markup::List: @type:BULLET:@items[ o:RDoc::Markup::ListItem:@label0; [o; ; [I"LMost importantly, the block that you pass to atomically may be executed;To:RDoc::Markup::Verbatim; [I"?more than once. In most cases your code should be free of ;TI"(side-effects, except for via TVar. ;T:@format0o;;0; [o; ; [I"OIf an exception escapes an atomically block it will abort the transaction.;T@o;;0; [o; ; [I"FIt is undefined behaviour to use callcc or Fiber with atomically.;T@o;;0; [o; ; [I"LIf you create a new thread within an atomically, it will not be part of;To;; [I"Athe transaction. Creating a thread counts as a side-effect. ;T;0o; ; [I"LTransactions within transactions are flattened to a single transaction.;T@o; ; [I" @example;To;; [I"a = new TVar(100_000) ;TI"b = new TVar(100) ;TI" ;TI"Concurrent::atomically do ;TI" a.value -= 10 ;TI" b.value += 10 ;TI"end;T;0: @fileI"lib/concurrent/tvar.rb;T:0@omit_headings_from_table_of_contents_below00I"