Created
July 6, 2020 05:40
-
-
Save HouzuoGuo/31e640d4f61229f3e76853bfa4537b05 to your computer and use it in GitHub Desktop.
Fix all sorts of timer and sleep issues for Ubuntu 20.04 running in WSL
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
Solution is taken from: https://github.com/microsoft/WSL/issues/4898#issuecomment-646790723 | |
cat <<'EOF' > nanosleep.c | |
#include <time.h> | |
#include <unistd.h> | |
int nanosleep(const struct timespec *req, struct timespec *rem) | |
{ | |
return clock_nanosleep(CLOCK_MONOTONIC, 0, req, rem); | |
} | |
int usleep(useconds_t usec) | |
{ | |
struct timespec req = { | |
.tv_sec = (usec / 1000000), | |
.tv_nsec = (usec % 1000000) * 1000, | |
}; | |
return nanosleep(&req, NULL); | |
} | |
EOF | |
gcc -shared -fPIC -o /usr/local/lib/libnanosleep.so nanosleep.c | |
echo '/usr/local/lib/libnanosleep.so' >> /etc/ld.so.preload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment