Thread overview |
---|
July 04, 2016 Error: incompatible types for 'shared(SysTime)' and 'shared(SysTime)' | ||||
---|---|---|---|---|
| ||||
if (curTime - lastMsgTime).total!"seconds") ... Both are shared Durations. also when I try to do lastMsgTime = curTime; Gives me Error: non-shared method std.datetime.SysTime.opAssign is not callable using a shared object. |
July 05, 2016 Re: Error: incompatible types for 'shared(SysTime)' and 'shared(SysTime)' | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luke Picardo | On Monday, 4 July 2016 at 20:54:53 UTC, Luke Picardo wrote:
> if (curTime - lastMsgTime).total!"seconds") ...
>
> Both are shared Durations.
>
> also when I try to do
>
> lastMsgTime = curTime;
>
> Gives me
>
> Error: non-shared method std.datetime.SysTime.opAssign is not callable using a shared object.
cast `shared` away. yes, this is how you supposed to use it now: cast it away.
|
July 05, 2016 Re: Error: incompatible types for 'shared(SysTime)' and 'shared(SysTime)' | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | On 07/05/2016 07:25 AM, ketmar wrote:
> cast `shared` away. yes, this is how you supposed to use it now: cast it
> away.
after having ensured thread safety that is
|
September 13, 2018 Re: Error: incompatible types for 'shared(SysTime)' and 'shared(SysTime)' | ||||
---|---|---|---|---|
| ||||
Posted in reply to ag0aep6g | On 07/05/2016 04:16 PM, ag0aep6g wrote:
> On 07/05/2016 07:25 AM, ketmar wrote:
>> cast `shared` away. yes, this is how you supposed to use it now: cast it
>> away.
>
> after having ensured thread safety that is
Sorry to resurrect an old thread, but then how can one update a SysTime field in a shared class? Like this (using a synchronized class for simplicity, this part works and the mutex acts as expected):
```
import std.concurrency;
import std.datetime.systime;
import core.thread;
public synchronized shared class A {
public:
void doSomething() {
// Doing something takes a couple of seconds.
Thread.sleep(2.dur!"seconds");
// How can we update the timestamp? Neither of those work
timestamp = Clock.currTime;
timestamp = cast(shared) Clock.currTime;
}
private:
SysTime timestamp;
}
void main() {
shared A a = new shared A;
spawn( (shared A a) { a.doSomething;}, a );
Thread.sleep(1.dur!"seconds");
spawn( (shared A a) { a.doSomething;}, a );
}
```
Of course the kludge (and what I'll be doing) is just to use __gshared, but I expected this to be a convenience / hack to save you castings, rather than the only way to achieve it.
A.
|
September 13, 2018 Re: Error: incompatible types for 'shared(SysTime)' and 'shared(SysTime)' | ||||
---|---|---|---|---|
| ||||
Posted in reply to Arafel | On 09/13/2018 03:25 PM, Arafel wrote:
> // How can we update the timestamp? Neither of those work
> timestamp = Clock.currTime;
> timestamp = cast(shared) Clock.currTime;
cast() timestamp = Clock.currTime;
|
September 14, 2018 Re: Error: incompatible types for 'shared(SysTime)' and 'shared(SysTime)' | ||||
---|---|---|---|---|
| ||||
Posted in reply to ag0aep6g | On 09/13/2018 06:59 PM, ag0aep6g wrote:
> On 09/13/2018 03:25 PM, Arafel wrote:
>> // How can we update the timestamp? Neither of those work
>> timestamp = Clock.currTime;
>> timestamp = cast(shared) Clock.currTime;
>
> cast() timestamp = Clock.currTime;
Still not there... it doesn't work with ref parameters (and probably other things, like AAs, or at least nested AAs / arrays):
```
import std.stdio;
import std.datetime.systime;
import core.time;
void foo(ref SysTime t) {
t += 1.dur!"minutes";
}
shared synchronized class A {
private SysTime s;
this() {
cast ()s = Clock.currTime; // OK, This works
}
void foo() {
writeln("A.foo - Before: ", cast() s);
// But how to do this??
//(cast () s).foo;
//s.foo;
writeln("A.foo - After: ", cast() s);
}
}
void main() {
SysTime s = Clock.currTime;
writeln("main - Before: ", s);
s.foo;
writeln("main - After: ", s);
shared A a = new shared A;
a.foo;
}
```
That makes me wonder if casting a lvalue makes sense at all, and how come that the result is not another lvalue... what it is, I don't know, because you can assign to it, but not take a reference.
|
Copyright © 1999-2021 by the D Language Foundation