Can the send function send an array?

Fox linuxl4 at sohu.com
Tue Sep 10 13:14:05 UTC 2024


// I am learning how to send and receive data. The following is 
my intention, but it cannot be compiled.
// aliases to mutable thread-local data not allowed, what does it 
mean? thank you.

I am learning how to send and receive. The following is my 
intention, but it cannot be compiled. Report
import std.concurrency;
import std.stdio;
import std.exception;

void main(){

         int N=5;
         int[] arr1= new int[N];
         for(int i; i<N; i++){ arr1[i]=i;}
         writeln("Main thread, msg= ", arr1);
         auto j=spawn(&fun);
         j.send(thisTid, arr1);   //error!
         enforce(receiveOnly!Tid() == j);

}

void fun(){

         auto msg5= receiveOnly!(Tid, int[])();
         writeln("child thread, msg= ", msg5[1]);
         msg5[0].send(thisTid);
}



More information about the Digitalmars-d-learn mailing list