use stm to wait for threads