-
Notifications
You must be signed in to change notification settings - Fork 124
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
Thread safety #300
Comments
Can you expand on this a bit? I mean, why does Smithay need to share (send?) Overall not opposed to making |
Generally it can be awkward in Rust to deal with types that don't implement
It shouldn't be too hard to just create an independent Edit: So this probably isn't essential for anything in Smithay, but it may be convenient if it could be improved. |
I drafted #540 for experimenting. The only value that can be modified, once the keymap is compiled, is the reference counter. Using atomics makes it thread-safe. WARNING: this alone does not make the keymap API thread-safe:
I see 2) to be the main blocker: if the context is not modified, no other keymap is compiled while the previous one is in use and a brand new state is created for each thread, then it should be “safe” if not using functions working with strings. |
Do you know if MSVC also supports C11 mutexes? If so, I guess we can add one to
TBH I always felt bad about this one, especially since it imposes a length limit on whatever is using it. I think we can consider thread safe alternatives for this.
I think it's OK to document the log set functions as being thread-unsafe, like must be done at init time or such.
State should not be thread safe IMO. Trying to use it from multiple threads is probably wrong. My suggestion would be to only look into if there's a valid use case. |
https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance lists |
Good to know, thanks. If threads.h is fully supported, then another, easy option for the xkb_context text buffer is to make it thread local ( |
I drafted #544 to make context buffer thread-safe. |
libxkbcommon
can be awkward to use in a multi-threaded context given the use of reference counting in a non-thread-safe way. In particular it's proven inconvenient with how Smithay (a Rust library for building compositors) wants to use types likexkb_keymap
.Would there be any interest in making libxkbcommon APIs thread safe? Making reference counting thread-safe should be relatively simple with atomic operations. That would be enough to make
xkb_keymap
thread safe since it is immutable... except it contains a reference toxkb_context
, which is reference counted and mutable. That is a bit more complicated to deal with.(I'm also not sure if libxkbcommon can be used in systems where atomics and mutexes wouldn't be available, or how that would best be addressed.)
The text was updated successfully, but these errors were encountered: