Behaves different on my osx and linux machines

Christian Köstlin christian.koestlin at gmail.com
Thu Dec 21 11:02:37 UTC 2023


I have this somehow reduced program that behaves differently on osx and 
linux.


```d
void stdioMain()
{
     import std.stdio : readln, writeln;
     import std.concurrency : spawnLinked, receive, receiveTimeout, 
LinkTerminated;
     import std.variant : Variant;
     import std.string : strip;
     import std.process : execute;
     import core.time : dur;
     auto input = spawnLinked(() {
             string getInput() {
                 writeln("Please enter something:");
                 return readln().strip();
             }
             string line = getInput();
             while (line != "quit")
             {
                 writeln("You entered ", line);
                 line = getInput();
             }
         });

     bool done = false;
     while (!done) {
         auto result = ["echo", "Hello World"].execute;
         if (result.status != 0)
         {
             throw new Exception("echo failed");
         }
         writeln(result.output);
         receiveTimeout(dur!"msecs"(-1),
           (LinkTerminated t) {
               writeln("Done");
               done = true;
           },
         );
     }
     writeln("ByeBye");
}

void main(string[] args)
{
     stdioMain();
}
`

It should just read from stdin in one separate thread and on the main 
thread it just executes one `echo` after the other (and tries to find 
out, if the other thread finished).

In linux this behaves as expected, meaning it prints a lot of hello worlds.

In osx on the other hand it prints 'please enter something', waits for 
my input, prints it, and outputs one hello world.

What did I do wrong?

Kind regards,
Christian

p.s.: i am using ldc-1.35.0 osx version is 13.6.


More information about the Digitalmars-d-learn mailing list