Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int can_go = 0;
- static pthread_mutex_t go_mtx = PTHREAD_MUTEX_INITIALIZER;
- static pthread_cond_t wait_cond = PTHREAD_COND_INITIALIZER;
- void set_go( void )
- {
- pthread_mutex_lock( &go_mtx );
- can_go = 1;
- pthread_cond_signal(&wait_cond);
- pthread_mutex_unlock( &go_mtx );
- }
- int wait_go( void )
- {
- pthread_mutex_lock( &go_mtx );
- while(can_go == 0)
- {
- printf("beging waiting ... n");
- pthread_cond_wait(&wait_cond, &go_mtx);
- printf("waiting donen");
- }
- printf("outside of while waiting !!!n");
- pthread_mutex_unlock( &go_mtx );
- }
- void *run_thread(viod *ptr)
- {
- ..............
- if (is_sync_thread){ //if this is a special sync thread, do something and trigger other threads
- .............
- set_go();
- }
- else{ //this is worker, wait for sync thread finish and set_go()
- wait_go()
- ....................
- }
- }
- beging waiting ...
- beging waiting ...
- beging waiting ...
- beging waiting ...
- beging waiting ...
- wait done
- outside of while waiting !!!
- outside of while waiting !!!
- outside of while waiting !!!
- outside of while waiting !!!
- outside of while waiting !!!
- outside of while waiting !!!
- outside of while waiting !!!
- outside of while waiting !!!
- outside of while waiting !!!
- outside of while waiting !!!
- outside of while waiting !!!
- outside of while waiting !!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement