LINUX.ORG.RU

pthread_cond_timedwait


0

0

Прошу не пинать сильно - первая попытка, но приведенный ниже код работает не совсем так, как хотелось бы. pthread_cond_timedwait - не ждет положенные ему параметром 5 секунд. checkpointCond никто не сигнализирует. Куда рыть? Делал все по примеру Advanced Linux Programming.

------------------------------- #include <time.h> #include <pthread.h>

void *checkpointProcess(void *param); pthread_t checkpointThreadID=(pthread_t)NULL; unsigned int checkpointDTime=0; pthread_cond_t checkpointCond; pthread_mutex_t checkpointMutex;

int checkpointStartup(unsigned int dTime){ int ret; if (!checkpointThreadID && dTime){ checkpointDTime=dTime; int ret=pthread_cond_init(&checkpointCond,NULL); ret=pthread_mutex_init(&checkpointMutex,NULL); pthread_mutex_unlock(&checkpointMutex); ret=pthread_create(&checkpointThreadID,NULL,&checkpointProcess,NULL); } else ret=0; return ret; }; int checkpointShutdown(){ if (checkpointThreadID){ checkpointDTime=0; pthread_cond_signal(&checkpointCond); pthread_join(checkpointThreadID,NULL); checkpointThreadID=0; checkpointDTime=0; pthread_mutex_destroy(&checkpointMutex); pthread_cond_destroy(&checkpointCond); }; }; void *checkpointProcess(void *param){ char tmp[1024]; while (checkpointDTime){ struct timespec aTime; int err; clock_gettime(CLOCK_REALTIME,&aTime); aTime.tv_sec+=checkpointDTime;

pthread_mutex_lock(&checkpointMutex); err=pthread_cond_timedwait(&checkpointCond,&checkpointMutex,&aTime ); pthread_mutex_unlock(&checkpointMutex);

if (checkpointDTime){ // Do anything }; }; return NULL; };

anonymous

Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.