Fix test/wait.c.

The test would fail sometimes due access to concurrent access to variable
"counter".