concurrentqueue
concurrentqueue copied to clipboard
BlockingConcurrentQueue::wait_dequeue_timed can't quit
Under Linux, there will be a time synchronization operation. The current time is March 12, 2022. If set to March 1, 2022, wait_time will not return.
Not sure I understand. Can you provide an example?
`#include
using namespace std; using namespace moodycamel;
void timeCallback() { system("date -s 2022-03-01"); }
int main() {
BlockingConcurrentQueue<int> queue;
// current time 2022-03-21
int value = 0;
queue.wait_dequeue_timed(value, 60 * 1000 * 1000);
//have function call timeCallback();
cout << "hello world" << endl;
return 0;
} `
hello world can't output
I see! This is because POSIX semaphores use absolute deadlines based on CLOCK_REALTIME. I'll see if I can conditionally detect the presence of a glibc 2.30 extension that would work with CLOCK_MONOTONIC instead.
I went to check the relevant information and it really has something to do with CLOCK_REALTIME
Yes. Glibc 2.30+ has a non-standard sem_clockwait
function that allows CLOCK_MONOTONIC time to be specified instead.
Should be fixed if you have glibc 2.30+ available.
I checked that my glibc is 2.25, so sem_clockwait is not supported, so only pthread_mutex_t and pthread_cond_t can be used to implement semaphores
pthread_cond_timedwait() with CLOCK_MONOTONIC is supported
pthread_mutex_t and pthread_cond_t are semaphores that I see in poco
pthread_cond_t
is a condition variable. It can be used to implement a semaphore but it's not as efficient. I'll see if I can add an optional alternative implementation that uses it though.