RejectedSoftware Forums

Sign up

question about Isolated template

How to send an Isolated object to other task?
This doesn't compile:

class Test{}
auto test = makeIsolated!Test;
send(tid, test.move);

And this also doesn't compile:

receive (
    (Isolated!Test){}
);

Reason is disabled copying of IsolatedRef and it is impossible to store isolated objects in Variant:

Variant test = makeIsolated!Test; // Error: struct vibe.core.concurrency.IsolatedRef!(Test).IsolatedRef is not copyable because it is annotated with @disable

Re: question about Isolated template

On Sun, 18 Aug 2013 15:40:14 GMT, Jack Applegame wrote:

How to send an Isolated object to other task?
This doesn't compile:

class Test{}
auto test = makeIsolated!Test;
send(tid, test.move);

And this also doesn't compile:

receive (
    (Isolated!Test){}
);

Reason is disabled copying of IsolatedRef and it is impossible to store isolated objects in Variant:

Variant test = makeIsolated!Test; // Error: struct vibe.core.concurrency.IsolatedRef!(Test).IsolatedRef is not copyable because it is annotated with @disable

I've just committed a change set that works around the Variant issue by using a temporary proxy struct. Should work fine now (I just didn't directly send Isolated!T values up to now and missed this error).

Re: question about Isolated template

Thanks!

Re: question about Isolated template

Another issue is creating isolated objects of abstract types.
For example:

pure A makeA(T)(T data) { return new B!T(data); }

abstract class A {
    void work();
}
class B(T) : A {
  override void work() { data.work(); }
  private this(T data) { _data = data; }
  T _data;
}

It is impossible to create Isolated!A object because A is abstract.
We need something like

pure auto makeIsolatedFactory(F, ARGS...)(F factory, ARGS args) if(isCallable!F) {
    return Isolated!(ReturnType!F)(factory(args));
}

or passing factory by template alias parameter (for templated factories)

Re: question about Isolated template

On Mon, 19 Aug 2013 23:04:57 GMT, Jack Applegame wrote:

Another issue is creating isolated objects of abstract types.
For example:

pure A makeA(T)(T data) { return new B!T(data); }

abstract class A {
    void work();
}
class B(T) : A {
  override void work() { data.work(); }
  private this(T data) { _data = data; }
  T _data;
}

It is impossible to create Isolated!A object because A is abstract.
We need something like

pure auto makeIsolatedFactory(F, ARGS...)(F factory, ARGS args) if(isCallable!F) {
    return Isolated!(ReturnType!F)(factory(args));
}

or passing factory by template alias parameter (for templated factories)

Sorry, I had completely overlooked this message. However, I have implemented opCast now to provide a solution to the issue. So this should work:

abstract class A {
  void work();
}
class B(T) : A {
  override void work() { data.work(); }
  private this(T data) { _data = data; }
  T _data;
}
Isolated!B makeA(T)(T data)
{
  return cast(Isolated!B)makeIsolated!A(data);
}

With some more compiler support it should also be possible to directly do this:

Isolated!B b = new A(data); // A.this() must be pure for this to work

Walter seemed to take a route that would allow this, but there as been no recent progress as far as I know.