Project

General

Profile

Feature #10867

An ATOMIC_GET operation should be written and used.

Added by sstewartgallus (Steven Stewart-Gallus) over 4 years ago. Updated about 2 months ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:68173]

Description

In some cases rb_atomic_t types are retrieved without synchronization.
Most cases in the code seem very innocuous and unlikely to cause bugs
but an evil optimizing compiler could potentially do bad things
(especially with link time optimization). Now, the raw machine code
is probably going to be safe on architectures such as x86 but the
compiler might drag the code around and mess it up. A very easy
temporary solution might be to redefine rb_atomic_t to be volatile.
Technically, according to the C11 standard such accesses don't count
as synchronized or atomic but in practise that would prevent compilers
from moving accesses around. I would prefer if an ATOMIC_GET define
is made and used instead though.

History

Updated by nobu (Nobuyoshi Nakada) over 4 years ago

  • Status changed from Open to Feedback

Won't atomic operations using gcc's __atomic/__sync built-ins or other platform-provided functions make such barriers?

Updated by kosaki (Motohiro KOSAKI) over 4 years ago

No.
If you need a synchronization, you must not use rb_atomic_t. That's a bug.

#4

Updated by jeremyevans0 (Jeremy Evans) about 2 months ago

  • Backport deleted (2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN)
  • ruby -v deleted (2.2.0)
  • Tracker changed from Bug to Feature

Also available in: Atom PDF