Thread overview
Behaves different on my osx and linux machines
Dec 22
Kagamin
Dec 27
Kagamin
Dec 27
Kagamin
December 21
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.
December 22

Add more debugging?

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

On Friday, 22 December 2023 at 15:02:42 UTC, Kagamin wrote:

>

Add more debugging?

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

Thanks for the suggestion. But it still behaves the same:
Output:

     Running vibe-io
1
Please enter something:
asdf
You entered asdf

Please enter something:
Hello World

3
1
asdf
You entered asdf

Please enter something:
Hello World

3
1
qwer
You entered qwer

Please enter something:
Hello World

3
1
December 27

Maybe write and read lock each other, try to use puts:

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

Maybe you're not supposed to print text while reading?

December 27

On Wednesday, 27 December 2023 at 14:03:06 UTC, Kagamin wrote:

>

Maybe you're not supposed to print text while reading?

In parallel I have contacted schveiguy on discord and he found the culprid. But we do not have a solution yet. It probably will result in a bugreport at https://issues.dlang.org/.

Kind regards,
Christian

December 28

On Wednesday, 27 December 2023 at 14:38:38 UTC, Christian Köstlin wrote:

>

On Wednesday, 27 December 2023 at 14:03:06 UTC, Kagamin wrote:

>

Maybe you're not supposed to print text while reading?

In parallel I have contacted schveiguy on discord and he found the culprid. But we do not have a solution yet. It probably will result in a bugreport at https://issues.dlang.org/.

Finally had some spare time, and created the issue:

https://issues.dlang.org/show_bug.cgi?id=24305

Might I say, this is a symptom of depending on C for buffered i/o, and I wish we didn't.

-Steve