[Issue 20936] New: core.sync.rwmutex should have shared overloads (and make it usable in @safe code)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jun 16 09:49:36 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20936
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 at puremagic.com
Reporter: er.krali at 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 {
public:
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
}
}
private:
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).
--
More information about the Digitalmars-d-bugs
mailing list