-
Notifications
You must be signed in to change notification settings - Fork 45
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 #184
Comments
Had an idea to help with some of the encoding overhead I was worried about. To reiterate, making device.destroy() internally synchronized means that if it actually does cause resources to be destroyed, every usage of the API needs to take a read-lock on the device's read-write-lock so that actual destruction doesn't race with some other thread using the device. Read-locks are unfortunate because internally they're bumping a counter of the number of readers. If you touch this counter from many threads, you invalidate the cache a lot and have a lot of write contention. Maybe your standard library implementation is clever to help avoid it. The overhead of the read-lock would be unfortunate for encoding operations, but one way to alleviate it would be to have the read-lock last as long as the encoder does. That way, device destruction doesn't happen until the encoder's last reference is dropped. |
A few cases I think we had conclusions on but I didn't write down:
|
No code change for this, so closing but keeping the |
This thread is for figuring out what operations are thread-safe (internally synchronized). Last weeek's webgpu.h meeting ended up discussing this as an offshoot of #9 because of the question of whether device.destroy() must be externally synchronized with encoding (i.e. a multithreaded application must add its own locks).
wgpu in safe Rust wouldn't allow this kind of unsafety, so it's more of a question of whether dawn and wgpu-core would have (unsafe) encoder methods that require external synchronization, perhaps alongside safe versions. In the safe version, each individual encoder command has to take a read-lock on the device's read-write-lock, or we would need something else clever, like a way for the entire encoder to take a lock until it's finished or dropped, without making it impossible to ever actually destroy a device.
I think we agreed to just go ahead with making these internally synchronized. Maybe in the future if we can't come up with something better and consider adding unsafe versions of encoder commands?
The text was updated successfully, but these errors were encountered: