Runtime-checked thread-safety for Weak - would it be safe?

Let's imagine there is another reference-counted type, call it Brc<T>.
Brc<T> itself is neither Send nor Sync, but its Weak type is always Send even if T isn't.
When upgrade is called on the Weak type, a runtime-check is performed to see if the current thread ID is the same of the thread that originally allocated Brc, and would fail if it isn't.

Would such behavior be safe?

Yes, I'm pretty sure that's safe. It doesn't provide any way to access a T value on a different thread.

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.