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
On Apple platforms (macOS, iOS, tvOS and watchOS), basically all UI code is required to run on the main thread.
In Xcode 9.0 Apple introduced the "Main Thread Checker", which is a way for developers to enable extra assertions to ensure that their application conform to these requirements.
It is unclear whether doing work off the main thread is UB in the strictest sense or not (depends on how atomic AppKit/UIKit's internal structures are, which I've yet to find documentation about), but I think cargo-careful would be a good place to enable such a thing anyhow.
Xcode enables it by default, and Apple's own documentation reports a 1–2% CPU overhead, so I don't think there's anything to be worried about there. Also, if AppKit or UIKit is not loaded into the process, the checker simply does nothing.
Enabling it is as simple as inserting a dynamic library:
(Of course an actual implementation in cargo-careful should use the current Xcode version via. xcode-select --print-path, and with proper error handling for people who don't have Xcode installed / have a too old version of Xcode to include that dylib).
For prosperity, I'll link this excellent blog post about the Main Thread Checker that outlines some undocumented options, if anyone's interested.
The text was updated successfully, but these errors were encountered:
I've never used an Apple device in my life, so I can't really comment on this, but if someone can figure out a reliable way to implement this automatically (ideally something tested by our CI, maybe behind a flag), then sure, sounds useful.
On Apple platforms (macOS, iOS, tvOS and watchOS), basically all UI code is required to run on the main thread.
In Xcode 9.0 Apple introduced the "Main Thread Checker", which is a way for developers to enable extra assertions to ensure that their application conform to these requirements.
It is unclear whether doing work off the main thread is UB in the strictest sense or not (depends on how atomic AppKit/UIKit's internal structures are, which I've yet to find documentation about), but I think
cargo-careful
would be a good place to enable such a thing anyhow.Xcode enables it by default, and Apple's own documentation reports a 1–2% CPU overhead, so I don't think there's anything to be worried about there. Also, if AppKit or UIKit is not loaded into the process, the checker simply does nothing.
Enabling it is as simple as inserting a dynamic library:
DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/usr/lib/libMainThreadChecker.dylib ./target/debug/my_binary
(Of course an actual implementation in
cargo-careful
should use the current Xcode version via.xcode-select --print-path
, and with proper error handling for people who don't have Xcode installed / have a too old version of Xcode to include thatdylib
).For prosperity, I'll link this excellent blog post about the Main Thread Checker that outlines some undocumented options, if anyone's interested.
The text was updated successfully, but these errors were encountered: