Closed Cassy343 closed 2 years ago
XCB is thread safe and Error
types do nothing but access data held behind the pointer, and eventually free
it.
Would there be a risk to double Drop
if it were Send
and Sync
?
ProtocolError
cannot be cloned. Could it be Send
but not Sync
?
Note that same would apply to Event
types.
As per the documentation of Sync
, a type T
is Sync
if and only if &T
is Send
. Basically the only things in the language that aren't Send
are raw pointers, and the only things that aren't Sync
are types with non-thread-safe interior mutability. If the the pointer held by the error and event types is unique, then the type should certainly be Send
, and as long as it has no interior mutability then it should also be Sync
.
I am not sure if this is intentional or not, but
xcb::ProtocolError
is neither Send nor Sync which makes working with this crate in a multithreaded environment pretty tedious. This appears to be due to each of the variants containing a type calledError
which all eventually boil down to a*mut xcb_generic_error_t
. Obviously it's unsound to send raw pointers between threads in the general case, but each of these error types seem to be freeing the pointer on drop, which suggests that this is an owning pointer, and thus safe to send between threads.