how to assign to shared obj.systime?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Fri Jul 10 07:06:33 UTC 2020


On Thursday, July 9, 2020 9:01:20 PM MDT mw via Digitalmars-d-learn wrote:
> On Friday, 10 July 2020 at 02:59:56 UTC, mw wrote:
> > Error: template std.datetime.systime.SysTime.opAssign cannot
> > deduce function from argument types !()(SysTime) shared,
> > candidates are:
> > /usr/include/dmd/phobos/std/datetime/systime.d(659,17):
> > opAssign()(auto ref const(SysTime) rhs)
>
> of course, better without casting.

Unless you're dealing with a primitive type that works with atomics, you
pretty much always have to cast when using shared (the only real exception
being objects that are specifically designed to work as shared and do the
atomics or casting internally for you). In general, when operating on a
shared object, you need to protect the section of code that's operating on
it with a mutex and then temporarily cast away shared to operate on the
object as thread-local. It's then up to you to ensure that no thread-local
references to the shared data escape the section of code protected by the
mutex (though scope may help with that if used in conjunction with
-dip1000).

- Jonathan M Davis





More information about the Digitalmars-d-learn mailing list