It does and shown here. Seeing two zeros in the output happens either way with the lock obtained inside or outside the while loop. The OP doesn't mention if such occurrence is valid. Therefore, likely not a problem.
Comment on Re^12: Threads sharing global variable (disingenous)