-
Notifications
You must be signed in to change notification settings - Fork 237
Description
The core-foundation-rs CFRunLoop
type does not appear to be marked as Send
or Sync
, and I suspect they should be.
Apple's Core Foundation docs appear to suggest those types are generally thread-safe (emphasis mine):
Core Foundation is sufficiently thread-safe that, if you program with care, you should not run into any problems related to competing threads. It is thread-safe in the common cases, such as when you query, retain, release, and pass around immutable objects. Even central shared objects that might be queried from more than one thread are reliably thread-safe.
Like Cocoa, Core Foundation is not thread-safe when it comes to mutations to objects or their contents. (...)
Looking at another usage, mozilla/authenticator-rs
passes a CFRunLoop
between threads in a SendableRunLoop
type: it schedules a CFRunLoopObserver
in a new thread, which then sends back the current CFRunLooop
over a mpsc::channel
and picks it up from the current thread.
The C __CFRunLoop
type also looks like it has a mutex around mutation operations (example), so it looks a lot like this should be safe to pass between threads... and you'd need to do this anyway if you want to schedule work on another thread.
Very few types in this crate (currently four) are marked as Send
or Sync
; and there's probably other types that could be marked that way too. Apple's documentation seems to suggest that Core Foundation types could be non-thread-safe (just you should assume safe unless otherwise stated), so I don't think that implementing Send + Sync
for T: TCFType
is wise.