s1543: acquire writer lock in right place, decrement thread counter properly