use pthread_mutex and pthread_condtion