{"id":175821,"date":"2013-04-08T01:56:03","date_gmt":"2013-04-07T21:56:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=175821"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=175821","title":{"rendered":"<span class=\"post_title\">Pthread_cond_timedwait: \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u044f<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435, \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0425\u0430\u0431\u0440\u0430\u044e\u0437\u0435\u0440\u044b!<\/p>\n<p>  \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044f \u0441\u0435\u0440\u0438\u044e \u043f\u043e\u0441\u0442\u043e\u0432 \u043f\u043e \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e, \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043a\u043e\u0441\u043d\u0443\u0442\u044c\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 Linux, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435 \u0438\u043c\u0435\u044e\u0449\u0435\u0439 \u043f\u043e\u043a\u0430 \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0433\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f (\u0430 \u043c\u043e\u0436\u0435\u0442 \u043e\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u043c\u043d\u0435). \u041c\u043d\u043e\u0433\u0438\u0435, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0434\u0430\u0436\u0435 \u043d\u0435 \u0434\u043e\u0433\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0441\u0442\u043e \u0431\u044b\u0442\u044c.<\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439:<\/p>\n<pre><code class=\"cpp\">struct timeval now; struct timespec timeout; gettimeofday(&now, 0); timeout.tv_sec = now.tv_sec + 2;      \/\/ 2 sec timeout.tv_nsec = now.tv_usec * 1000; \/\/ nsec  retval=0; pthread_mutex_lock(&mutex); while(!somethingHappens() && retval==0) {     retval=pthread_cond_timedwait(&condition, &mutex, &timeout); } pthread_mutex_unlock(&mutex); <\/code><\/pre>\n<p>  <a name=\"habracut\"><\/a>\u0421\u043c\u044b\u0441\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f pthread_cond_timedwait \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u043b\u0438\u0431\u043e \u0434\u043e\u0436\u0438\u0434\u0430\u0435\u043c\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u0430 (pthread_cond_signal \u0438\u043b\u0438 pthread_cond_broadcast) \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e somethingHappens(), \u0438\u043b\u0438 \u0436\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0430\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u043f\u043e \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u043c\u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0430. \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0444\u0440\u0430\u0437\u044b \u0438 \u043a\u0440\u043e\u0435\u0442\u0441\u044f \u0442\u0430 \u0441\u0430\u043c\u0430\u044f \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430! \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432\u0440\u0435\u043c\u044f, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0440\u0435\u0442\u044c\u0435\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0432 pthread_cond_timedwait, \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u043c \u0432\u0438\u0434\u0435! \u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0432\u0440\u0435\u043c\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043d\u043e \u043d\u0430\u0437\u0430\u0434(!) \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f (gettimeofday) \u0438 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0443\u0441\u043d\u0435\u043c \u0432 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0438 \u043d\u0430 pthread_cond_timedwait?<\/p>\n<p>  \u041a\u0430\u043a\u043e\u0432\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 pthread_cond_timedwait, \u0435\u0441\u043b\u0438 \u043d\u0430\u0448 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0443\u0436\u0435 \u0441\u043f\u0438\u0442 \u043d\u0430 \u044d\u0442\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435? \u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u0447\u0438\u0441\u0442\u043e! \u041d\u0430 \u0432\u0441\u0435\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\u0445, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044f \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442 \u0441 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430\u0437\u0430\u0434, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u043e\u0441\u044c, \u0442.\u0435. \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0430 \u0432\u0440\u0435\u043c\u044f \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0438\u0437 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u0433\u043e \u043a \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u043d\u0435 \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u043e \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0438? \u042d\u0442\u043e \u0431\u044b \u0440\u0435\u0448\u0438\u043b\u043e \u0432\u0441\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b!<\/p>\n<p>  \u041a\u0440\u0438\u0442\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u0440\u0430\u0437\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u043f\u0440\u0435\u043d\u0435\u0431\u0440\u0435\u0436\u0438\u043c\u043e \u043c\u0430\u043b\u043e\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u043e\u043f\u0430\u043b \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u044d\u0442\u043e\u0442 \u043d\u0438\u0447\u0442\u043e\u0436\u043d\u043e \u043c\u0430\u043b\u044b\u0439 \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430. \u041f\u043e\u0437\u0432\u043e\u043b\u044c\u0442\u0435 \u043d\u0435 \u0441\u043e\u0433\u043b\u0430\u0441\u0438\u0442\u044c\u0441\u044f. \u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0435\u0441\u043b\u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0435 \u0440\u0430\u0432\u043d\u0430 \u043d\u0443\u043b\u044e, \u0442\u043e \u043e\u043d\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f (\u043f\u0440\u0438\u043d\u044f\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u00ab\u0433\u0435\u043d\u0435\u0440\u0430\u043b\u044c\u0441\u043a\u0438\u043c \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u043c\u00bb), \u0430 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0432\u0441\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u041c\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0441 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432\u0438\u0434\u0435\u043e\u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f, \u0430 \u044d\u0442\u043e \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 (thread-\u043e\u0432), \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f pthread_cond_timedwait \u0440\u0430\u0437 \u044d\u0434\u0430\u043a 25 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u0447\u0430\u0441 \u043d\u0430\u0437\u0430\u0434 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0441 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\u044e, \u0431\u043b\u0438\u0437\u043a\u043e\u0439 \u043a 100%, \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e\u0442\u043e\u043a \u0434\u0430 \u0438 \u0437\u0430\u0441\u043d\u0435\u0442 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0447\u0430\u0441 \u043f\u043b\u044e\u0441 1\/25 \u0441\u0435\u043a\u0443\u043d\u0434\u044b!<\/p>\n<p>  \u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c?<\/p>\n<p>  \u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0441\u043a\u0430\u0437\u0430\u043b \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u043f\u043e\u0432\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0435\u0442, \u043d\u043e \u0438 \u043d\u0435 \u0440\u0435\u0448\u0430\u0442\u044c \u0435\u0435 \u0432\u043e\u0432\u0441\u0435, \u043d\u0435\u043b\u044c\u0437\u044f! \u0412 \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043c\u044b \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a, \u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e \u00ab\u043f\u043e\u0442\u043e\u043a\u043e\u043c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438\u00bb, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u00ab\u043f\u0435\u0440\u0435\u0432\u043e\u0434\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430\u0437\u0430\u0434\u00bb \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0445 \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u00ab\u0431\u0443\u0434\u0438\u0442\u00bb \u0432\u0441\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u0422.\u0435. \u043f\u043e \u0441\u0443\u0442\u0438, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0447\u0442\u043e-\u0442\u043e \u0442\u0430\u043a\u043e\u0435:<\/p>\n<pre><code class=\"cpp\">class SystemTimeManager { public:     SystemTimeManager();     ~SystemTimeManager();      void registerCond(pthread_mutex_t *mutex, pthread_cond_t *cond);     void unregisterCond(pthread_cond_t *cond);  private:     static void *runnable(void *ptr);  private:     time_t _prevSystemTime;     pthread_t _thread;     bool _finish;     pthread_mutex_t _mutex;     std::map&lt;pthread_cond_t *, pthread_mutex_t *&gt; _container; };  SystemTimeManager::SystemTimeManager ():     _prevSystemTime(time(0)),     _finish(false) {     pthread_mutex_create(&_mutex, 0);     pthread_create(&_thread, 0, runnable, this); }  SystemTimeManager::~SystemTimeManager() {     _finish=true;     pthread_join(_thread, 0);     pthread_mutex_destroy(&_mutex); }  void SystemTimeManager::registerCond(pthread_mutex_t *mutex, pthread_cond_t *cond) {     pthread_mutex_lock(&_mutex);     _container.insert(std::make_pair(cond, mutex));     pthread_mutex_unlock(&_mutex); }  void SystemTimeManager::unregisterCond(pthread_cond_t *cond) {     pthread_mutex_lock(&_mutex);     std::map&lt;pthread_cond_t *, pthread_mutex_t *&gt; it=_container.find(cond);     if(it!=_container.end())         _container-&gt;erase(it);     pthread_mutex_unlock(&_mutex); }  void * SystemTimeManager::runnable(void *ptr) {     SystemTimeManager *me=reinterpret_cast&lt; SystemTimeManager *&gt;(ptr);     while(!_finish)     {         If(time(0)&lt;_prevSystemTime)         {             pthread_mutex_lock(&me-&gt;_mutex);             for(std::map&lt;pthread_cond_t *, pthread_mutex_t *&gt; it=_container.begin();                  it!=_container.end(); ++it)             {                  pthread_mutex_lock(it-&gt;second);                  pthread_cond_broadcast(it-&gt;first);                  pthread_mutex_unlock(it-&gt;second);             }             pthread_mutex_unlock(&me-&gt;_mutex);         }         _prevSystemTime=time(0);     } } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 SystemTimeManager \u0438 \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0435\u043c \u0432\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u043d\u0430\u043c\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435.<\/p>\n<p>  \u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 \u043d\u0430 \u0442\u0435\u043c\u0443 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u00ab\u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u044f\u00bb. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u044f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043e\u043f\u0438\u0441\u0430\u043b \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043f\u0443\u0441\u0442\u044c \u0438 \u043d\u0435 \u0441\u0430\u043c\u043e\u0435 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e\u0435, \u044f \u043f\u0440\u0438\u0432\u0435\u043b \u2013 \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043e\u043d\u043e \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u2013 \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u044e \u2014 \u044f \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043c\u043e\u0433\u0443 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u0435\u0437 \u0432\u0430\u0441, \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0425\u0430\u0431\u0440\u0430\u044e\u0437\u0435\u0440\u044b. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u0443 \u043a\u043e\u0433\u043e-\u0442\u043e \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0434\u0440\u0443\u0433\u0438\u0435, \u0431\u043e\u043b\u0435\u0435 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b?    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/company\/nordavind\/blog\/175821\/\"> http:\/\/habrahabr.ru\/company\/nordavind\/blog\/175821\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435, \u0443\u0432\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0425\u0430\u0431\u0440\u0430\u044e\u0437\u0435\u0440\u044b!<\/p>\n<p>  \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044f \u0441\u0435\u0440\u0438\u044e \u043f\u043e\u0441\u0442\u043e\u0432 \u043f\u043e \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e, \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043a\u043e\u0441\u043d\u0443\u0442\u044c\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 Linux, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435 \u0438\u043c\u0435\u044e\u0449\u0435\u0439 \u043f\u043e\u043a\u0430 \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0433\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f (\u0430 \u043c\u043e\u0436\u0435\u0442 \u043e\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u043c\u043d\u0435). \u041c\u043d\u043e\u0433\u0438\u0435, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0434\u0430\u0436\u0435 \u043d\u0435 \u0434\u043e\u0433\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0441\u0442\u043e \u0431\u044b\u0442\u044c.<\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439:<\/p>\n<pre><code class=\"cpp\">struct timeval now; struct timespec timeout; gettimeofday(&#038;now, 0); timeout.tv_sec = now.tv_sec + 2;      \/\/ 2 sec timeout.tv_nsec = now.tv_usec * 1000; \/\/ nsec  retval=0; pthread_mutex_lock(&#038;mutex); while(!somethingHappens() &#038;& retval==0) {     retval=pthread_cond_timedwait(&#038;condition, &#038;mutex, &#038;timeout); } pthread_mutex_unlock(&#038;mutex); <\/code><\/pre>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-175821","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/175821","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=175821"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/175821\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=175821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=175821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=175821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}