How to pack types with variables in one message to send it to another thread? [tuple]
hane via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Sep 7 05:08:56 PDT 2014
On Sunday, 7 September 2014 at 10:42:37 UTC, MarisaLovesUsAll
wrote:
> Hi!
> I'm trying to make my program multithreaded, and I was stuck at
> messaging between threads.
> I need to pack types and variables into one message. Will I use
> Tuples or something?
>
> e.g.
>
> class Sprite {};
>
> send(tid, Sprite, "create", myInt);
>
> ................
>
> Also I don't understand how to use Variant. Messages can be
> different, and I don't know how to extract data from variant.
>
> send(tid, "One", "Two", myInt);
>
> receive(
> (Variant args)
> {
> /*
> args contains Tuple!(string, string, int)("One", "Two",
> 42);
> I need simple access to data, e.g. args[0] args[1]
> args[2]
> but I don't know how to do this
> because `.get` method need precise type of Tuple
> */
> }
> );
>
> Regards,
> MarisaLovesUsAll
receive() automatically expands tuples into multiple arguments.
receive((string s, string t, int i) { });
More information about the Digitalmars-d-learn
mailing list