pthread_cond_timedwait()

前端 未结 7 1560
有刺的猬
有刺的猬 2020-12-16 05:22
void wait(int timeInMs)
{
    struct timespec timeToWait;
    timeToWait.tv_sec = 5;
    timeToWait.tv_nsec = timeInMs*1000;

    int rt;

    pthread_mutex_lock(&am         


        
7条回答
  •  醉酒成梦
    2020-12-16 06:08

    Considering you are using timespec, and your goal isn't to synchronize but to wait I'd suggest nanosleep.

    #include 
    
    .
    .
    .
    
      struct timespec remain;
      remain.tv_sec = 5;
      remain.tv_nsec = timeInMs * 1000;
    
      do {
        if ( nanosleep( &remain, &remain ) == 0 || errno != EINTR ) {
          break;
        }
      } while ( 1 );
    
    .
    .
    .
    

提交回复
热议问题