Can't create "shared" Mutex with "-preview=nosharedaccess"

Gavin Ray ray.gavin97 at gmail.com
Sun Aug 28 21:15:59 UTC 2022


Example below:

- https://ldc.godbolt.org/z/aj7xdbb76

The following error is thrown, which I am not sure I understand 
since it's part of the initialization/ctor code for the shared 
resource:

```d
<source>(27): Error: direct access to shared `new 
shared(ReadWriteMutex)(Policy.PREFER_WRITERS)` is not allowed, 
see `core.atomic`
```

```d
import core.sync.rwmutex : ReadWriteMutex;

// The below works:
//
// 
https://github.com/dlang/dmd/commit/63cb064d3f62317159f999477c9dc15a5ca7d632#diff-652a0df83aadb85a63bc618ed724c49f6b7d4ea45d679ace8c7c90ea9c032537
struct Child
{
     this(int) shared {}
}

struct Parent
{
     shared Child ch;
     this(int i) shared
     {
         ch = shared Child(i);
     }
}

// But this doesn't?
class DiskManager
{
     shared ReadWriteMutex dbIOMutex;

     this() shared
     {
         this.dbIOMutex = new shared ReadWriteMutex();
     }
}
```


More information about the Digitalmars-d mailing list