Issue #12607 has been updated by Student (Nathan Zook).


I think that you might not have understood his concern.  Getting multi-threaded code right is hard, no matter the primitives available.  "People who know well about thread programming can use this feature using concurrent-ruby and I don't want to recommend it for people who don't know about threading well."  The issue is about setting traps for the unwary.

I think that it is interesting that the original discussing was around doing an atomic "++" -- because "++" and even "+" are not atomic in C.

I spent a few years doing assembler, mostly in PowerPC.  PowerPC (as of 10 years ago) did not have any instruction comparable to the X86 compare and exchange.  It does make sense, strictly from a performance standpoint, to have a mutex capability that can be dropped down to a few integer instructions.  But doing that requires that you understand exactly how those instructions work in the major architectures.  Given that the Ruby Integer class can spill any cache line, it is nonsensical to talk about fast locks using it.  You would want a register-sized value in some sort of wrapping class.

In my mind, it is a matter of boosting performance at the risk of creating traps for unwary programmers.  So far as I'm concerned, ruby's metaprogramming capacity has already filled the wind in those sails.  Therefore, I would be in favor of a robust, fast atomic capacity.  But not with the Integer class.  You really need to go with a 32-bit integer to maintain compatibility.

If you need more than 32 bits in your concurrency primitives, you had BETTER be brewing your own extensions. ;)


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

* Author: shyouhei (Shyouhei Urabe)
* Status: Feedback
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
* ruby -v: 
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
(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/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>