Very limited shared promotion
aliak
something at something.com
Mon Jun 24 22:06:03 UTC 2019
On Monday, 24 June 2019 at 13:20:23 UTC, Jonathan M Davis wrote:
> However, one issue with that from a usability perspective is
> that even if you're doing all of the right stuff like
> protecting access to the shared variable via a mutex and then
> temporarily casting it to thread-local to operate on it while
> the mutex is locked, if you want to actually assign anything to
> the shared variable before releasing the mutex, you'd have to
> use a pointer to it that had been cast to thread-local, whereas
> right now, you're actually allowed to just assign to it. e.g.
>
> shared MyClass obj;
>
> synchronized(mutex)
> {
> obj = cast(shared)someObj;
> }
>
> works right now, but if writing to shared variables were
> illegal like it arguably should be, then you'd have to do
> something ugly like
>
> shared MyClass obj;
>
> synchronized(mutex)
> {
> auto ptr = cast(MyClass*)&obj;
> *ptr = someObj;
> }
You can have the same usability/aesthetics:
synchronized {
cast(MyClass)obj = someObj;
}
Doesn't that work?
Ideally though, I think you'd want:
class MyClass {
void opAssign(MyClass c) shared { ... }
}
More information about the Digitalmars-d
mailing list