Last active
September 14, 2021 09:10
-
-
Save stepancheg/198db4623a20aad2ad7cddb8fda4a63c to your computer and use it in GitHub Desktop.
Bug in pthread_cond_timedwait in OSX with superlong timeout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <pthread.h> | |
int main() { | |
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; | |
pthread_cond_t condvar = PTHREAD_COND_INITIALIZER; | |
int r = pthread_mutex_lock(&mutex); | |
if (r != 0) { | |
perror("pthread_mutex_lock"); | |
return 1; | |
} | |
time_t now = time(0); | |
struct timespec timeout = { | |
// this version properly waits | |
//.tv_sec = now + 0x100000000000000 - 0x1000000, | |
// this exits immediately with unknown error 316 | |
.tv_sec = now + 0x100000000000000, | |
.tv_nsec = 0, | |
}; | |
printf("timespec %lld %lld\n", (long long) timeout.tv_sec, (long long) timeout.tv_nsec); | |
int r2 = pthread_cond_timedwait(&condvar, &mutex, &timeout); | |
if (r2 != 0) { | |
perror("pthread_cond_timedwait"); | |
return 1; | |
} | |
printf("$\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment