进程间信号互斥

转载请注明来源: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

来源:python脚本自动迁移

posted @ 2020-06-23 18:03  jiangcheng_15  阅读(206)  评论(0编辑  收藏  举报