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

Resolves #1199.