You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In GDScript, reading and writing elements from multiple threads is OK, but anything that changes the container size (resizing, adding or removing elements) requires locking a mutex.
Since the Dictionary is reference-counted, it would be possible to mutate state from an other thread, which is unsound without mutex. We also don't have access to the reference count itself.
This will be quite an involved addition. It's easy to make a newtype for the dictionary that ensures exclusive access to the dictionary for the right methods. However since a dictionary can store arbitrary values, that means this dictionary could be used to smuggle a non-send value between threads, or to smuggle a reference to a non-sync value between threads.
It would be nice to have such a newtype wrapper, but it'll require a bit of care to make it safe. Perhaps even forbidding the use of Gd<T> values in the dictionary.
How we enforce that is a big harder. We might need some recursive constructor that check every key/value for a non-send/sync value and reject those keys/values. This should probably also come with an unsafe constructor that doesn't check for this.
And of course we'd need to deep duplicate any dictionary used in this newtype.
Closing as there is currently no way to safely implement this. For more general discussion about threading design, we can use #18.
If you need this in an unsafe way, you can write a wrapper UnsafeDict(Dictionary) which implements Send -- but then it's your responsibility to keep up the guarantees.
I don't even know if it possible, but it would be awesome.
Sync would be a blast, too.
I need it to be able to use crossbeam with gdext.
The text was updated successfully, but these errors were encountered: