在6个测试人员中,有一个用户在只显示以下内容的线路上遇到崩溃
someDispatchQueue.sync { //Thread 0 crash
someDispatchQueue不能为nil,因为它正被声明为
在课程开始时使用let someDispatchQueue = DispatchQueue(label: "SomeDispatchQueue")。
我能想到的坠机原因只有两个:
A)关于它的调用方式的问题,例如
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + delay) {
//a few functions in between
someDispatchQueue.sync {也许你不能在main.async{}中调用customQueue.sync{}?然而,这个测试人员是唯一经历过这种崩溃的人,而其他5个测试人员也可以99%确定地运行这个功能-没有任何问题。它在我的设备上运行也没有问题。
B)日志的指示行为off
Swift崩溃日志是否应该显示崩溃的确切位置?或者可以少几行?日志中显示以下内容:
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000100f2f95c
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [6599]
Triggered by Thread: 0
Thread 0 name:
Thread 0 Crashed:
0 AppName 0x0000000100f2f95c closure #1 in FileDB.prepareFile() + 508 (<compiler-generated>:0)
1 AppName 0x0000000100f39734 partial apply for thunk for @callee_guaranteed () -> () + 20 (<compiler-generated>:0)
2 AppName 0x0000000100f2ccf4 thunk for @escaping @callee_guaranteed () -> () + 20 (<compiler-generated>:0)
3 libdispatch.dylib 0x000000019770c33c _dispatch_client_callout + 20 (object.m:495)
4 libdispatch.dylib 0x00000001977191f4 _dispatch_lane_barrier_sync_invoke_and_complete + 60 (queue.c:996)
5 AppName 0x0000000100f2f6b4 FileDB.prepareFile() + 264 (FileDB.swift:138) //line 138 is the someDispatchQueue.sync {
6 AppName 0x0000000100f79844 ICEFrameworkHandler.initiateWrite() + 728 (ICEFrameworkHandler.swift:254)
7 AppName 0x0000000100f78e18 closure #1 in ICEFrameworkHandler.delayRun(delay:stamp:) + 140 (ICEFrameworkHandler.swift:164) //the function that calls the DispatchQueue.main.asyncAfter
8 AppName 0x0000000100f7e508 thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:0)
9 libdispatch.dylib 0x000000019770c33c _dispatch_client_callout + 20 (object.m:495)
10 libdispatch.dylib 0x000000019770eaf8 _dispatch_continuation_pop + 408 (inline_internal.h:2484)
11 libdispatch.dylib 0x000000019771f624 _dispatch_source_invoke + 1224 (source.c:568)
12 libdispatch.dylib 0x00000001977184f0 _dispatch_main_queue_callback_4CF + 560 (inline_internal.h:2525)
13 CoreFoundation 0x00000001979e76b0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 (CFRunLoop.c:1749)
14 CoreFoundation 0x00000001979e22c8 __CFRunLoopRun + 1708 (CFRunLoop.c:3069)
15 CoreFoundation 0x00000001979e18f4 CFRunLoopRunSpecific + 480 (CFRunLoop.c:3192)
16 GraphicsServices 0x00000001a1df8604 GSEventRunModal + 164 (GSEvent.c:2246)
17 UIKitCore 0x000000019bbb5358 UIApplicationMain + 1944 (UIApplication.m:4823)
18 AppName 0x0000000100f150b4 main + 68 (AppDelegate.swift:19)
19 libdyld.dylib 0x000000019785d2dc start + 4@matt
let someDispatchQueue = DispatchQueue(label: "SomeDispatchQueue")
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
someDispatchQueue.sync {
print("someDispatchQueue.sync") //prints first, no exception
}
print("end of asyncAfter()") //prints second, reaches statement without exception
}发布于 2020-07-10 09:26:22
这一行:
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + delay) {...proves,当我们到达这里时,我们就在主队列上。好,现在:
someDispatchQueue.sync {哇哦!当你在主队列中时,千万不要说sync。这是因为sync的意思是“阻止我;我想停下来等待另一个队列完成下一个任务。”但是“me”是主队列;你永远不能阻塞主队列。
https://stackoverflow.com/questions/62825525
复制相似问题