Thread: refactor latch by adding an internal counter that has an associated condition_variable and add doc.