Does anyone understand how to use "shared" types with concurrency send/receive functions?

Arek via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 14 13:13:28 PDT 2017


On Monday, 14 August 2017 at 19:22:23 UTC, Steven Schveighoffer 
wrote:
> On 8/13/17 11:40 PM, Jonathan M Davis via Digitalmars-d-learn 
> wrote:
>> On Saturday, August 12, 2017 18:57:44 Arek via 
>> Digitalmars-d-learn wrote:
>>> I have the folowing problem:
>>> I like to envelope the class object in struct to control the
>>> destruction moment and then send this object to another
>>> thread/fiber (or task, cause I use vibe-d).
>>>
>>> I can't find any method to make it working. Any ideas?
>> 
>> Unfortunately, send and receive do not currently work with 
>> shared because of
>> issues with Variant, which they use internally.
>
> This can't be a correct statement. This is the whole point of 
> shared.
>
> -Steve

First of all, I'm not native English speaker, so forgive me 
possible misunderstanding

In my opinion the whole problem of 'shared' is that when I use 
send/receive operation (I believe it's should be something 
similar to go's channels or erlang messages) I do not want to 
share the memory so any "shared" concept is useless.

What I really would like to get is possibility to make:

// in first thread
Unique!MyObject msg = new MyObject()
send(msg.release);

// in other thread:
auto msg = receiveOnly!(Unique!MyObject)();


My object disappears in "send" operation and its new instance is 
constructed on receive.
If I can ensure the uniqueness of the object, there is no need to 
"share" it or synchronize the access.

But now such operation is impossible and the compiler forces me 
to cope with shared if MyObject has any references to other areas 
of memory.

Anyway, thanks for all replies.

Arek



More information about the Digitalmars-d-learn mailing list