From: nobu@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:101951] [Ruby master Feature#14706] Atomic Integer incr/decr
Date: Wed, 06 Jan 2021 10:34:22 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-89804.20210106103421.1320@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-14706.20180423205312.1320@ruby-lang.org
Issue #14706 has been updated by nobu (Nobuyoshi Nakada).
Status changed from Open to Closed
Closed due to duplication.
----------------------------------------
Feature #14706: Atomic Integer incr/decr
https://bugs.ruby-lang.org/issues/14706#change-89804
* Author: mperham (Mike Perham)
* Status: Closed
* Priority: Normal
----------------------------------------
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.
~~~ ruby
counter = 0
counter.incr # => 1
counter.incr(10) # => 11
counter.incr(-1) # => 10
counter.reset # => 10
counter # => 0
~~~
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2021-01-06 10:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-14706.20180423205312.1320@ruby-lang.org>
2021-01-05 20:18 ` [ruby-core:101938] [Ruby master Feature#14706] Atomic Integer incr/decr dsisnero
2021-01-06 10:34 ` nobu [this message]
2021-01-06 15:14 ` [ruby-core:101961] " dsisnero
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-89804.20210106103421.1320@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).