Acess variable that was set by thread

Ali Çehreli acehreli at
Mon Aug 8 13:53:35 UTC 2022

On 8/8/22 00:14, vc wrote:

 > i will like to hear thoughts even if it works
 > for me

__gshared would work as well but I would consider std.concurrency first. 
Just a simple example:

import std.stdio;
import std.concurrency;
import core.thread;

struct Result {
   int value;

struct Done {

void run()
   bool done = false;
   while (!done) {
     writeln("Derived thread running.");
         (Done msg) {
             done = true;

   // Send the result to the owner
   // (I made assumptions; the thread may produce
   // results inside the while loop above.)

void main()
     auto worker = spawn(&run);
     auto result = receiveOnly!Result();
     writeln("Here is the result: ", result);

Related, Roy Margalit's DConf 2022 presentation was based on traps 
related to sequential consistency. The video will be moved to a better 
place but the following link should work for now:


More information about the Digitalmars-d-learn mailing list