www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - readln() blocks file operations on windows

reply Martin Drasar via Digitalmars-d <digitalmars-d puremagic.com> writes:
Hi,

consider this code:

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

void tryOpen()
{
  Thread.sleep(2.seconds);
  try {
    auto f = File("nonexistent");
  }
  catch (Exception e) {
    writeln("Could not open a file");
  }
}

void main()
{
  spawn(&tryOpen);
  readln();
}


On Linux, it works as expected, showing a "Could not open a file" after
two or so seconds. On windows, however, the file opening gets blocked
until a line is read from stdin.

Is this a feature or a bug? If it is a feature, it certainly is not
documented.

Cheers,
Martin
Jul 31 2014
parent reply "FreeSlave" <freeslave93 gmail.com> writes:
Note that output to stdout is not good choice to check event 
order, because it's buffered. Try to flush stdout or write to 
stderr. Maybe it's actual problem.
Jul 31 2014
parent reply Martin Drasar via Digitalmars-d <digitalmars-d puremagic.com> writes:
On 31.7.2014 20:37, FreeSlave via Digitalmars-d wrote:
 Note that output to stdout is not good choice to check event order,
 because it's buffered. Try to flush stdout or write to stderr. Maybe
 it's actual problem.
Hi, this is just for illustration, although I think that writeln flushes itself. I was checking it in a debugger after it suddenly hung my entire program. Martin
Jul 31 2014
parent "Inspi8" <leni50 web.de> writes:
On Thursday, 31 July 2014 at 19:13:28 UTC, Martin Drasar via 
Digitalmars-d wrote:
 On 31.7.2014 20:37, FreeSlave via Digitalmars-d wrote:
 Note that output to stdout is not good choice to check event 
 order,
 because it's buffered. Try to flush stdout or write to stderr. 
 Maybe
 it's actual problem.
Hi, this is just for illustration, although I think that writeln flushes itself. I was checking it in a debugger after it suddenly hung my entire program. Martin
Hi, It works under Windows wenn compiled as a 64-bit program ( -m64 )
Aug 05 2014