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

Consider using a semaphore rather than a pipe on Unix? #125

Open
karlmcdowall opened this issue Jan 15, 2025 · 1 comment
Open

Consider using a semaphore rather than a pipe on Unix? #125

karlmcdowall opened this issue Jan 15, 2025 · 1 comment

Comments

@karlmcdowall
Copy link

Hi!

Background

I've been looking at some of the open issues on the Rust-coreutils project. In order to verify compatibility of the new Rust implementation with the established GNU implementation, the project is aiming to get all of the existing GNU-coreutils tests to pass when the tests are run against the new Rust implementations.
The specific issue I'm looking at is here - basically a couple of the tests (sort-merge-fdlimit.sh and sort-continue.sh) use ulimit to limit the number of file-descriptors available to the process under test (in this case it's the sort command).
Debugging has shown that in order to actually get the number of file descriptors required down the level that GNU-sort uses, we can't afford the two pipes that are required for the current rust-ctrlc implementation (specifically on the unix build).

Proposal

One potential solution is to use a libc anonymous semaphore rather than the pipe to signal from the signal-handler to the blocked-thread that makes the client-callback. sem_post is specified to be safe to use from a signal-handler. This removes the overhead of the two file-descriptors for the pipe used in the current implementation.

I've done a prototype implementation and it seems to work, will post that shortly as a pull-request. Hopefully that will clearly demonstrate the proposal.

Please let me know your thoughts! For my implementation I've put the pipe vs semaphore choice under a feature-flag, but maybe we don't need the pipe implementation any more with if we just go with using a semaphore? Or maybe that's too risky for everyone else out there?!

Thanks,
Karl

@karlmcdowall
Copy link
Author

I've posted my prototype implementation here to hopefully help with the discussion.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant