Fixed race condition in Latch.

There is a race condition in Latch. The same pid can be terminated by
2 seperate threads simultaneously.

Review: https://reviews.apache.org/r/26783