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

For issue '"threads" test has a race condition #1199', pls help review it.