Description
Bugzilla Link | 48560 |
Version | 11.0 |
OS | Linux |
Reporter | LLVM Bugzilla Contributor |
CC | @mclow |
Extended Description
lib++ uses nanosleep in __libcpp_thread_sleep_for like this:
while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR);
On Linux, such a nanosleep loop can run forever because of a Linux bug that's documented here:
https://man7.org/linux/man-pages/man2/nanosleep.2.html#BUGS
For this to happen the thread needs to receive signals at a high frequency which seems to be rather uncommon.
https://github.com/golang/proposal/blob/5b63da9579c3b19294be614dcad33e20a9a4ad22/design/24543-non-cooperative-preemption.md
https://github.com/golang/go/blob/go1.15.6/src/runtime/signal_unix.go#L347
https://github.com/golang/go/blob/go1.15.6/src/runtime/preempt.go#L223
This could lead to problems when on Linux, native code that uses libc++ is called from a Go thread. The Go thread executing this_thread::sleep_for will loop forever calling nanosleep and the other Go thread that tries to preempt it will also loop forever, perpetually trying to preempt it.
I know this is a Linux bug, but since a lot of people are using Linux it might be worth implementing a workaround in libc++.