Crashes when the class is destructed, how to handle unfinished semaphore?
class CrashTestViewCtrl: UIViewController { private var semaphore = DispatchSemaphore(value: 2) override func viewDidLoad() { super.viewDidLoad() DispatchQueue.global().async { [weak self] in self?.semaphore.wait() // do something ...... } } deinit { print("……deinit……") }}