On 12/10/2015 02:07 PM, Entity325 wrote:

> Both threads need to be able to run asynchronously themselves, so message
> passing using std.concurrency isn't an option.

I can still imagine a case where the receiver checks the message queue with a timeout of 0, which is non-blocking.

> My problem is: every time I try to declare a shared object in D from a
> non-shared memory space, I get a compiler error: [object] is not callable
> using a non-shared object.

Instead of "[object]", the message actually contains a member function name, right? If so, here is a reduction:

class C {
    void foo() shared {  // <-- note shared
    }
}

void main() {
    auto c = new C();
    c.foo();
}

Error: shared method deneme.C.foo is not callable using a non-shared object

But that's the reverse of what you said: In my case I am constructing a non-shared object. Here is another one where the whole class is shared:

shared class C {  // <-- note shared
    void foo() {
    }
}

void main() {
    auto c = new C();
    c.foo();
}

> most frustrating was the guy who responded to a similar inquiry with "Have
> you checked out std.parallelism and std.concurrency?" Cute.

Perhaps that was me because it is always at the tip of my lips. :) The response is valuable because there are so many problems with data-sharing concurrency.

> 1: attempting to assign a shared object to a non-shared memory
> space(easy to fix)

I can't reproduce the same error message with that one.

> 2: attempting to assign a non-shared object to a shared memory
> space(less easy to fix, but still not bad)

Ditto.

> 3: attempting to assign a shared object to a shared memory space from
> within a non-shared memory space(no clue)

I don't think these are about assignment.

> 4: attempting to create a shared object from within a non-shared memory
> space(how am I supposed to create shared objects if I can't do it from a
> non-shared space?)

In this context 'shared' is like 'const'. You can put that attribute to individual member functions, including the constructor:

import std.stdio;

class C {
    this(int i) {
        writefln("Constructing non-shared with %s", i);
    }

    this(int i) shared {
        writefln("Constructing     shared with %s", i);
    }
}

void main() {
    auto c = new C(1);
    auto c2 = new shared(C)(2);
}

Constructing non-shared with 1
Constructing     shared with 2

Ali

Reply via email to