Project

General

Profile

Actions

Feature #14706

closed

Atomic Integer incr/decr

Added by mperham (Mike Perham) almost 6 years ago. Updated about 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:86657]

Description

Ruby does not any thread-safe way to implement simple counters without a Mutex. Today Ruby provides Integer#succ but this funcalls "+", making it thread-unsafe as far as I know.

I'd propose adding Integer#incr(amount=1) and Integer#reset which would use atomic operations, giving us thread-safe, high-performance counters.

counter = 0
counter.incr # => 1
counter.incr(10) # => 11
counter.incr(-1) # => 10
counter.reset # => 10
counter # => 0

Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Feature #12607: Ruby needs an atomic integerFeedbackko1 (Koichi Sasada)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0