[process] Fix process-unref-race.exe (#4144)
authorLudovic Henry <ludovic@xamarin.com>
Thu, 15 Dec 2016 13:18:23 +0000 (08:18 -0500)
committerGitHub <noreply@github.com>
Thu, 15 Dec 2016 13:18:23 +0000 (08:18 -0500)
commit3a185940f933f3d6fc11e39e832032e6efaa3f5f
treefabf0ff5ccf8949c35dbb35b0097f2aeb6c20b0a
parent8995297d8ae76187171252a083f9eb29994a2067
[process] Fix process-unref-race.exe (#4144)

* [process] Rename MonoProcess to Process as it's not public anymore

* [process] Replace setting process->pid = 0 by process->signalled = TRUE

* [process] Remove processes_mutex lock when unrefing process->handle

We do not need to synchronize it here because we do not modify `processes`, and the only other place where we access process->handle is before adding it to `processes`.

* [process] Fix race condition

Without this memory barrier `process->next = processes` and `processes = process` could be reordered, and when accessing `processes` in mono_sigchld_signal_handler, we could observe a NULL processes->next. This would make us not find a pid in `processes`, and because of the posix API, we would never mark this process as exited.

This would trigger a hang in `process-unref-race.exe` test.

Thank you to @kumpera for the help figuring this out!
mono/metadata/w32process-unix.c