进程间信号互斥
转载请注明来源:https://www.cnblogs.com/hookjc/
sem_trywait[fail]->sem_post->sem_timedwait->write/read
sem_trywait[succ]->sem_post->sem_timedwait->write/read-sem_post
int sem_timedwait_millsecs(sem_t *sem, long msecs)
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
long secs = msecs/1000;
msecs = msecs%1000;
long add = 0;
msecs = msecs*1000*1000 + ts.tv_nsec;
add = msecs / (1000*1000*1000);
ts.tv_sec += (add + secs);
ts.tv_nsec = msecs%(1000*1000*1000);
return sem_timedwait(sem, &ts);
}
创建并初始化时的锁定
windows / mutex
Linux / link: PTHREAD_PROCESS_SHARED cond mutex