-
Notifications
You must be signed in to change notification settings - Fork 91
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
Need a spinlock that never uses std::thread::yield_now #97
Comments
Hello. This is an interesting (and frustrating) product of cargo's somewhat bizarre feature flag logic. This makes me wonder whether, instead of an Edit: One such problem could be that an |
There's also some potentially relevant discussion on this thread |
This sounds like the same issue. |
It seems to me that a client could have three possible requirements: a) They may always need an async-signal-safe lock. (My case.) I would say these are all useful and reasonable. So perhaps what the crate should do is:
The By putting all three in submodules of |
I'm wondering about an alternate approach that has the mutex generic over a "yield policy" (perhaps with a better name like "relax"). Something like the following: pub trait Yield {
fn yield();
} This crate could provide the existing policies like |
This seems like a reasonable suggestion. If anybody wants to open a PR to add this I'd be grateful. If not, I'll have the time to implement it in a few weeks. |
Yeah yield policy parameter + features for default yield policy sounds good. |
I've opened #102. However, it still has unresolved problems relating to type inference (more information in the PR). If anybody has any ideas about this, please put them in the PR. |
#102 has now been merged and included in version |
This use case may be a little obscure, so "we don't support that" is a perfectly reasonable response. But, just in case:
On a POSIX system, I have some shared data which I need to access from multiple threads but also from a signal handler. This is generally not possible:
Mutex
is based onpthread_mutex
, which is not async-signal-safe.I can work around 2) by simply blocking the signals whenever I hold the lock.
I was hoping to use this crate to work around 1), but the
std
feature means that I cannot count on this crate's spinlocks not to usestd::thread::yield_now
, which (oddly) is not async-signal-safe.Even if I don't enable the
std
feature myself, crates used by multiple dependents are compiled with the union of the features requested by all those dependents. So if my crate happens to be used with someone else who wantsspin
with thestd
feature, then I getlibc::sched_yield
calls in my signal handlers.My concerns would be addressed if there were a separate
Mutex
type that was guaranteed never to usesched_yield
or any other non-async-signal-safe system calls, regardless of which features were enabled.Thanks for your consideration!
The text was updated successfully, but these errors were encountered: