Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::thread::sleep does not document its interaction with signals #129136

Open
GKFX opened this issue Aug 15, 2024 · 4 comments
Open

std::thread::sleep does not document its interaction with signals #129136

GKFX opened this issue Aug 15, 2024 · 4 comments
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@GKFX
Copy link
Contributor

GKFX commented Aug 15, 2024

Location

std::thread::sleep

Summary

POSIX permits the C function sleep to be implemented using the SIGARLM signal (sleep(3)), meaning it is non-portable to mix use of that signal with sleep. The nanosleep function, which std::thread::sleep uses, is required by POSIX not to interfere with signals (nanosleep(2)), so it should in fact be OK currently to mix std::thread::sleep with SIGALRM. However, this is not actually documented. Given that the Rust function is called "sleep" it is easy to be concerned that there might be a problem.

Could std::thread::sleep make a documented commitment not to interfere with SIGALRM?

@GKFX GKFX added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Aug 15, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 15, 2024
@workingjubilee
Copy link
Member

The documentation is out of date, at least one platform implements it via usleep.

@workingjubilee
Copy link
Member

The same website documents this as unspecified: https://man7.org/linux/man-pages/man3/usleep.3.html#CAVEATS

@saethlin saethlin added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 21, 2024
@workingjubilee
Copy link
Member

Interestingly, @ivmarkov notes that ESP-IDF doesn't support signals and thus the interaction of usleep with them is irrelevant, but I feel less confident that such should apply to all platforms past and future?

I also feel less confident that all platforms that claim to implement POSIX correctly implement POSIX.

@workingjubilee
Copy link
Member

@GKFX Do you actually need a documented commitment (true going forward) or do you simply want a statement that currently thread::sleep does not affect SIGALRM on any platform which also implements POSIX signals?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants