[Issue 12133] New: Relaxed read-modify-write for shared lvalues

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 11 15:31:34 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=12133

           Summary: Relaxed read-modify-write for shared lvalues
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: druntime
        AssignedTo: nobody at puremagic.com
        ReportedBy: stanislav.blinov at gmail.com


--- Comment #0 from Stanislav Blinov <stanislav.blinov at gmail.com> 2014-02-11 15:31:31 PST ---
TDPL prohibits using operators on shared variables. I.e. this:

shared int i;
++i;

is illegal. It is stated that core.atomic should be used instead:

shared int i;
atomicOp!"+="(i, 1);

However, there are cases when this can introduce unnecessary performance loss:
e.g. private shared variables that are only ever accessed under a lock.

I'm proposing to add two functions to core.atomic to allow for operations on
shared variables without atomicOp()'s performance penalties:

1) localOp:

performs and acquire-op-release, e.g.:

shared int i;
auto v = localOp!"+="(i, 1);

Useful when there's still need for ordering. Though I don't really like the
name "localOp".

2) assumeLocal:

converts shared lvalue to a non-shared lvalue, e.g:

shared int i;
++assumeLocal(i);

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list