Logo

Programming-Idioms

History of Idiom 33 > diff from v6 to v7

Edit summary for version 7 by :

Version 6

2015-08-21, 23:14:19

Version 7

2015-09-03, 17:05:00

Idiom #33 Atomically read and update variable

Assign variable x the new value f(x), making sure that no other thread may modify x between the read and the write.

Idiom #33 Atomically read and update variable

Assign variable x the new value f(x), making sure that no other thread may modify x between the read and the write.

Imports
require 'atomic'https://github.com/ruby-concurrency/atomic
Code
x = Atomic.new(0)
x.update { |x| f(x) }
Doc URL
https://github.com/ruby-concurrency/atomic
Origin
https://github.com/ruby-concurrency/atomic