objc2_foundation/
thread.rs

1use core::panic::{RefUnwindSafe, UnwindSafe};
2
3use crate::NSThread;
4
5use objc2::MainThreadMarker;
6
7unsafe impl Send for NSThread {}
8unsafe impl Sync for NSThread {}
9
10impl UnwindSafe for NSThread {}
11impl RefUnwindSafe for NSThread {}
12
13/// Whether the application is multithreaded according to Cocoa.
14pub fn is_multi_threaded() -> bool {
15    NSThread::isMultiThreaded()
16}
17
18/// Whether the current thread is the main thread.
19///
20/// Deprecated. Prefer `MainThreadMarker::new().is_some()` or
21/// `NSThread::isMainThread_class()` instead.
22#[deprecated = "use `objc2::MainThreadMarker::new().is_some()`"]
23pub fn is_main_thread() -> bool {
24    MainThreadMarker::new().is_some()
25}
26
27#[allow(unused)]
28fn make_multithreaded() {
29    let thread = unsafe { NSThread::new() };
30    unsafe { thread.start() };
31    // Don't bother waiting for it to complete!
32}