Linux" sem_wait"伪?

时间:2016-01-09 02:49:22

标签: linux

我真正想知道的是,如果/* simple strtol wrapper with error checking */ long xstrtol (char *p, char **ep, int base) { errno = 0; long tmp = strtol (p, ep, base); /* Check for various possible errors */ if ((errno == ERANGE && (tmp == LONG_MIN || tmp == LONG_MAX)) || (errno != 0 && tmp == 0)) { perror ("strtol"); exit (EXIT_FAILURE); } if (*ep == p) { fprintf (stderr, "No digits were found\n"); exit (EXIT_FAILURE); } return tmp; } 是"没有忙碌等待"或不。如果线程在sem_wait()中等待其请求的资源,则会浪费CPU周期。

1 个答案:

答案 0 :(得分:0)

通常,同步原语将线程添加到等待队列,然后将其置于休眠状态。当资源可用时,它会唤醒一个或多个线程,这些线程随后将再次尝试请求,并且可能会或可能不会重新进入休眠状态,具体取决于它们是否获取了所请求的资源。