Does anyone understand how to use "shared" types with concurrency send/receive functions?
Arek via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Aug 13 04:35:05 PDT 2017
On Sunday, 13 August 2017 at 02:50:13 UTC, crimaniak wrote:
> On Saturday, 12 August 2017 at 18:57:44 UTC, Arek 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?
>
> I tried it too some time ago. Then I read Alexandrescu book and
> realized that the authors of the language do not want anyone to
> do this. Long story short, just plan your application so that
> each complex object is monitored by only one thread/task, and
> pass not objects, but messages (immutable structs) about what
> to do with them.
Yeah, I've read this. But conurrency.send cannot pass immutable
object. The same story with Unique.
What means, that if I have complex objects which I want to
transfer between threads I must keep them somewhere in global
memory and share among threads. I can use send/receive only to
signal availability of their existance. What I need is kind of
"move" operation beetwen threads.
More over, "shared" looks rather like unfinished concept. It is
really difficult to create proper struct (with postblit and
destructor) working as shared object.
I even have no clue what is exact semantics of "shared" types.
Language specification is a little laconic.
Anyway, _gshared looks very promising, so I will try to work out
any approach.
Thanks for answer.
Arek
More information about the Digitalmars-d-learn
mailing list