Skip to content

Commit

Permalink
Use threads only for git processes on windows
Browse files Browse the repository at this point in the history
On Ubuntu, threads can cause seg faults, see:
HaxeFoundation/neko#281
  • Loading branch information
tobil4sk committed Apr 6, 2023
1 parent 8fb8206 commit b8c24a7
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions src/haxelib/api/Vcs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -192,28 +192,39 @@ abstract class Vcs implements IVcs {
// just in case process hangs waiting for stdin
p.stdin.close();

final streamsLock = new sys.thread.Lock();
function readFrom(stream:haxe.io.Input, to: {value: String}) {
to.value = stream.readAll().toString();
streamsLock.release();
}

final out = {value: ""};
final err = {value: ""};
Thread.create(readFrom.bind(p.stdout, out));
Thread.create(readFrom.bind(p.stderr, err));
final ret = if (Sys.systemName() == "Windows") {
final streamsLock = new sys.thread.Lock();
function readFrom(stream:haxe.io.Input, to:{value:String}) {
to.value = stream.readAll().toString();
streamsLock.release();
}

final code = p.exitCode();
for (_ in 0...2) {
// wait until we finish reading from both streams
streamsLock.wait();
}
final out = {value: ""};
final err = {value: ""};
Thread.create(readFrom.bind(p.stdout, out));
Thread.create(readFrom.bind(p.stderr, err));

final ret = {
code: code,
out: out.value,
err: err.value
final code = p.exitCode();
for (_ in 0...2) {
// wait until we finish reading from both streams
streamsLock.wait();
}
{
code: code,
out: out.value,
err: err.value
};
} else {
final out = p.stdout.readAll().toString();
final err = p.stderr.readAll().toString();
final code = p.exitCode();
{
code: code,
out: out,
err: err
};
};

p.close();
return ret;
}
Expand Down

0 comments on commit b8c24a7

Please sign in to comment.