ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: daniel@dan42.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:102079] [Ruby master Feature#12607] Ruby needs an atomic integer
Date: Thu, 14 Jan 2021 02:25:07 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-89938.20210114022501.10@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-12607.20160721050407.10@ruby-lang.org

Issue #12607 has been updated by Dan0042 (Daniel DeLorme).


chrisseaton (Chris Seaton) wrote in #note-28:
> For example for issuing unique IDs across multiple Ractors.

That's the "monotonically increasing counter" case I was talking about, and for that I really think a generator (like the above `MyCounter.next`) is a more appropriate tool than an atomic integer.

> For example a CAS to update a bank balance is a common requirement.

Can you elaborate? In my experience financial transactions will be handled at the DB level. Not to mention you usually need more intricate synchronization such as atomic update of the balances of _two_ accounts. I don't quite see how an atomic integer is a realistic tool for money stuff.

> I can only offer that I use atomic integers for many things fairly frequently in my working life.

That's great, so you should easily be able to give a concrete example _other_ than generating unique sequential IDs. I'm quite curious, so looking forward to a nice realistic use case.

----------------------------------------
Feature #12607: Ruby needs an atomic integer
https://bugs.ruby-lang.org/issues/12607#change-89938

* Author: shyouhei (Shyouhei Urabe)
* Status: Feedback
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
----------------------------------------
(This one was derived from bug #12463)

Although I don't think += would become atomic, at the same time I understand Rodrigo's needs of _easier_ counter variable that resists inter-thread tampering.  I don't think ruby's Integer class can be used for that purpose for reasons (mainly because it is not designed with threads in mind).  Rather we should introduce a integer class which is carefully designed.

Why not import Concurrent::AtomicFixnum into core?



-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2021-01-14  2:25 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-12607.20160721050407.10@ruby-lang.org>
2021-01-06 12:06 ` [ruby-core:101956] [Ruby master Feature#12607] Ruby needs an atomic integer eregontp
2021-01-06 15:17 ` [ruby-core:101962] " dsisnero
2021-01-12  7:54 ` [ruby-core:102026] " ko1
2021-01-12 11:13 ` [ruby-core:102031] " eregontp
2021-01-13  7:32 ` [ruby-core:102056] " ko1
2021-01-13 18:05 ` [ruby-core:102070] " daniel
2021-01-13 21:45 ` [ruby-core:102074] " chris
2021-01-13 22:40 ` [ruby-core:102075] " marcandre-ruby-core
2021-01-13 23:45 ` [ruby-core:102076] " chris
2021-01-14  2:25 ` daniel [this message]
2021-01-14  2:34 ` [ruby-core:102080] " chris
2021-01-14  3:41 ` [ruby-core:102082] " daniel
2021-01-14 13:06 ` [ruby-core:102091] " eregontp
2021-01-14 14:43 ` [ruby-core:102095] " daniel
2021-01-29  8:59 ` [ruby-core:102291] " ko1
2021-01-29 12:28 ` [ruby-core:102299] " eregontp
2022-07-25 13:14 ` [ruby-core:109315] " Eregon (Benoit Daloze)
2022-07-25 14:22 ` [ruby-core:109316] " chrisseaton (Chris Seaton)

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-89938.20210114022501.10@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).