This is the follow-up to D19122, which was accepted but subsequently reverted due to a bug it introduced (that I didn't see during local testing on Windows but which manifested quite often on Linux). That bug (a race between the Process object was being destroyed and the thread terminating, caused by the join not being done under certain conditions) is fixed in this version of the patch.
This patch fixes various races between the time the private state thread is signaled to exit and the time it actually exits (during which it no longer responds to events). Previously, this was consistently causing 2-second timeout delays on process detach/stop for us.
This also prevents crashes that were caused by the thread controlling its own owning pointer while the controller was using it (copying the thread wrapper is not enough to mitigate this, since the internal thread object was getting reset anyway). Again, we were seeing this consistently.
For what it's worth, I've run the test suite with this change (on Linux) without any regressions, and the number of reruns dropped from 15 to 0 for me (though that last part may be coincidence).