www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20936] New: core.sync.rwmutex should have shared overloads


          Issue ID: 20936
           Summary: core.sync.rwmutex should have shared overloads (and
                    make it usable in  safe code)
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: er.krali gmail.com

In the same way core.sync.mutex has.

Currently a ReadWriteMutex that is an internal member of a shared class /
struct has to cast away shared to be usable.

This leads to the following ugliness:

import core.sync.rwmutex;

class C {
    shared this() {
        rwmutex = cast(shared) new ReadWriteMutex(); // This is bad, but...

    shared int readData() {
        synchronized((cast ()rwmutex).reader) { // ... this is ugly as hell
            // Let's get some data here
            return 42;

    shared void setData(int data) {
        synchronized((cast ()rwmutex).writer) { // ditto
            // Store data here

    ReadWriteMutex rwmutex;

void main() {
    shared C c = new shared C();

It probably should get the same kind of `shared` overloads that the normal
Mutex did.

Also, it prevents it from being used in  safe code (although the class is not
 safe at all, it probably could be with little effort).

Jun 16 2020