use pthread_barrier instead of sleep() in 'threads' test

For issue '"threads" test has a race condition #1199', pls help review it.
We should still sleep() because we want to write out some '.'s before sending the signal, and calling sleep() makes that much more likely.