I'm having trouble with Linux's sem_timedwait() function. For some reason it returns a "timeout" immediately after being called with a 0.5sec timeout. Therefore the DeadlockDetect thread misfires on Linux.
Does anyone have any experience with this?
For those of you with Linux, can you compile and run this quick test program?
When run, it should print something like
I'm interested in the results - are you getting zero ticks as well? Where's the bug?
Does anyone have any experience with this?
For those of you with Linux, can you compile and run this quick test program?
#include <time.h> #include <stdlib.h> #include <stdio.h> #include <semaphore.h> #include <errno.h> int main(void) { sem_t sem; if (sem_init(&sem, 0, 0)) { printf("sem_init failed\n"); return 1; } timespec timeout; timeout.tv_sec = 1; timeout.tv_nsec = 500 * 1000 * 1000; clock_t Begin = clock(); int res = sem_timedwait(&sem, &timeout); clock_t End = clock(); printf("sem_timedwait: %d, errno %d, %llu ticks\n", res, errno, (long long)(End - Begin)); sem_destroy(&sem); return 0; }Compile with (assuming test.cpp is the filename):
Code:
g++ test.cpp -lpthread
When run, it should print something like
Code:
sem_timedwait: -1, errno 110, 0 ticks