-
Notifications
You must be signed in to change notification settings - Fork 2
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
ThreadSafe type’s value property? #108
Comments
Hi @mattmassicotte 👋🏼 |
It does provide a consistent read, but it returns the value. From that point on, it's no longer being protected by the queue. This could be safe, depending on/why it is being protected. But, it is not safe in the general case. To provide full safety, you would have to always access the value externally using |
Correct, if you're working with mutable reference types there is a window for a race conditions there unless they also enforce internal thread safety. I forget if there was a specific need for this in For mutating structs though, one would only be able to set the result in a later call to As is it's intended to be easy read and after that the value (should be) disconnected from the type using 100% open to questions or feedback on this approach as is, naming and threading are hard 😆 |
That said, it's probably a good idea to keep this type |
Unfortunately, neither of these constructs are safe in the general case. Once Now, it could be that this turns out to be fine! The compiler cannot reason about all possible uses. But, as a rule, a type like this that permits a protected value to escape the protection is usually a problem. |
I completely missed the fact that the returned type needs to be protected. In the context of how the utility is used by Command, since we mutate it within the block to concatenate the output, it should be safe, no? I'll go ahead with @waltflanagan's suggestion to change the visibility of this utility.
Out of curiosity, how would you recommend tackling scenarios like this? I'm still early in my understanding of strict concurrency, so I'm not entirely sure what the best practices is here:
Thanks a lot folks ❤️ |
Hello! Was just glancing though the sources, and I took note of the ThreadSafe type. It looks to me like the value property allows you to escape the queue. Am I understanding correctly?
The text was updated successfully, but these errors were encountered: