linux线程的挂起与恢复

#include #include #include #include pthread_mutex_t wqy_mutex_pause = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t wqy_cond_pause = PTHREAD_COND_INITIALIZER; bool wqy_pthread_pause = false; void wqy_pthread_suspend(void) { if (wqy_pthread_pause == false) { pthread_mutex_lock( &wqy_mutex_pause ); wqy_pthread_pause = true; printf("------pthread pause------/n"); pthread_mutex_unlock( &wqy_mutex_pause ); } else { printf("pthread suspend already/n"); } } void wqy_pthread_resume(void) { if (wqy_pthread_pause == true) { pthread_mutex_lock(&wqy_mutex_pause); wqy_pthread_pause = false; pthread_cond_broadcast(&wqy_cond_pause); printf("------pthread resume------/n"); pthread_mutex_unlock(&wqy_mutex_pause); } else { printf("pthread resume already/n"); } } void wqy_pthread_pause_location(void) { pthread_mutex_lock(&wqy_mutex_pause); while(wqy_pthread_pause) { pthread_cond_wait(&wqy_cond_pause, &wqy_mutex_pause); } pthread_mutex_unlock(&wqy_mutex_pause); }

 

你可能感兴趣的:(linux线程的挂起与恢复)