Thread overview
[Issue 21033] enhancement: allow assign to field when the shared owing object has been locked already without cast
Jul 10, 2020
mw
Dec 17, 2022
Iain Buclaw
Dec 20, 2023
Nick Treleaven
Dec 28, 2023
anonymous4
Dec 28, 2023
anonymous4
Dec 28, 2023
anonymous4
July 10, 2020
https://issues.dlang.org/show_bug.cgi?id=21033

--- Comment #1 from mw <mingwu@gmail.com> ---
Created attachment 1797
  --> https://issues.dlang.org/attachment.cgi?id=1797&action=edit
enhancement: allow assign to field when the shared owing object has been locked
already without cast

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=21033

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--
December 20, 2023
https://issues.dlang.org/show_bug.cgi?id=21033

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick@geany.org

--- Comment #2 from Nick Treleaven <nick@geany.org> ---
hasIndirections!SysTime is true, so in theory `time` can't have `shared` cast away safely. See issue #24269. However, it looks like the only indirection is to immutable data:

    long  _stdTime;
    Rebindable!(immutable TimeZone) _timezoneStorage;

So actually the cast might be safe.

--
December 28, 2023
https://issues.dlang.org/show_bug.cgi?id=21033

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from anonymous4 <dfj1esp02@sneakemail.com> ---
This can be done only for value types, shared and immutable data. For thread local mutable reference types lock doesn't provide thread safety, because you escape thread local data into shared context. What you ask can't be for all reference types. Whether it can be done for SysTime is a SysTime's problem.

--
December 28, 2023
https://issues.dlang.org/show_bug.cgi?id=21033

--- Comment #4 from anonymous4 <dfj1esp02@sneakemail.com> ---
(In reply to anonymous4 from comment #3)
> What you ask can't be for all reference types.
can't be done

--
December 28, 2023
https://issues.dlang.org/show_bug.cgi?id=21033

--- Comment #5 from anonymous4 <dfj1esp02@sneakemail.com> ---
You can store Duration:
class A {
        Duration unixTime;
        synchronized void setTime(ref SysTime t) {
                unixTime = t-epoch;
        }
        synchronized SysTime getTime() {
                return epoch+unixTime;
        }
}

--