-
Notifications
You must be signed in to change notification settings - Fork 525
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
Implement Send
and Sync
for HANDLE
#3169
Comments
See #3093 (comment) |
I'm using |
@ChrisDenton @dpaoliello Thoughts on this? It's my understanding |
It's a good question, but I think the answer is unfortunately a mixture of these factors:
It's a good question, but unfortunately I think the answer is "there isn't a single good answer". The right answer is building safe abstractions on top of those types. Each of those safe abstractions can determine whether |
My thinking was: The The But if I zoom out and look at the concurrency experience that Rust is trying to sell, I think I agree with you. |
A handle, in general, is a nebulous term that covers many different things and I'm not sure how well the metadata can distinguish. But if we're talking specifically about a kernel object type of handle then these should by themselves always be thread safe. Yes, things like |
The trouble is, Sending the bit pattern of |
Apologies, but I was sent here from #3181 -- it seems this ticket is closed as well however. Which issue is correct for this? |
@NuSkooler I think they're both closed as "can't be fixed". In Firezone I just created a worker thread to solve it, since it's hard to prove that my code is thread-safe otherwise. :/ Can't do much for now |
If you happen to know that your particular use of a handle is thread-safe then you can certainly wrap the handle in your own type that is |
@ReactorScram @kennykerr thanks for your quick response. In my particular case, it's with I do wonder: Would it be fruitful to supply a generic wrapper struct that can be used along with some of these APIs? |
In my case, I'm using a HANDLE from a CreateMutex. It's only purpose is to be sent between threads, so I need a workaround. I tried creating a wrapper:
But I still get |
I (hope) I found a solution:
|
Casting to |
Suggestion
In #3111,
windows-rs
changesHANDLE
,HMONITOR
, and other similar types fromisize
toc_void
. From my limited knowledge of the Win32 API, I think thatHANDLE
,HMONITOR
, and similar structures should be thread-safe and can be safely sent across threads. Am I correct in this assumption? I apologize if this is a naive question.If these types are thread-safe, can
windows-rs
implSend
andSync
for them? If not, what is the best practice for sending these pointers across threads? Thanks in advance.The text was updated successfully, but these errors were encountered: