jeremyczhen / fdbus

FDBus - Fast Distributed Bus
https://blog.csdn.net/jeremy_cz/article/details/89060291
161 stars 85 forks source link

CBaseSemaphore 系统时间变化,卡掉的问题 #9

Open mao3511 opened 4 years ago

mao3511 commented 4 years ago

BaseWorker 默认创建 CThreadEventLoop ;

Linux 平台,其 dispatch函数中会用到信号量操作,其中信号量的超时时间用到了:

clock_gettime(CLOCK_REALTIME) + sem_timedwait

再运行过程中,如果系统时间有变化,会不会导致卡死卡死状态?

jeremyczhen commented 4 years ago

This is really a problem. For QNX, sem_timedwait_monotonic() solve the problem, but it is a BB OS extension. For Linux, there is no replacement. One workaround is to create worker with FDB_WORKER_ENABLE_FD_LOOP asserted. The flag force event loop to use poll() rather than sem_timedwait(), which can avoid the issue. Long-term solution: QNX - sem_timedwait_monotonic() Linux - futex() or cond var Windows - unchanged.