尝试在GCDAsyncSocket队列上创建信号量并获取nil而不是......我在这里缺少什么?
dispatch_semaphore_t s = dispatch_semaphore_create(0);
// s == nil here !?!
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSAppleScript *run = [[NSAppleScript alloc] initWithSource:script];
eventDesc = [run executeAndReturnError:&errorDict];
dispatch_semaphore_signal(s);
});
dispatch_semaphore_wait(s, 15 * NSEC_PER_SEC);
这是堆叠竞赛
<_NSCallStackArray 0x604000529d10>(
0 ??? 0x00000001043ef09f 0x0 + 4366200991,
1 Remote for Mac 0x0000000100008520 main + 0,
2 Remote for Mac 0x00000001001a216f -[HTTPConnection replyToHTTPRequest] + 3743,
3 Remote for Mac 0x00000001001b2eeb -[HTTPConnection socket:didReadData:withTag:] + 7643,
4 Remote for Mac 0x00000001000de635 __37-[GCDAsyncSocket completeCurrentRead]_block_invoke + 405,
5 libclang_rt.asan_osx_dynamic.dylib 0x000000010096220f __wrap_dispatch_async_block_invoke + 271,
6 libdispatch.dylib 0x00000001018b1cfe _dispatch_call_block_and_release + 12,
7 libdispatch.dylib 0x00000001018a878c _dispatch_client_callout + 8,
8 libdispatch.dylib 0x00000001018bf93f _dispatch_queue_serial_drain + 205,
9 libdispatch.dylib 0x00000001018b1aa2 _dispatch_queue_invoke + 1174,
10 libdispatch.dylib 0x00000001018aaa0c _dispatch_root_queue_drain + 671,
11 libdispatch.dylib 0x00000001018aa71d _dispatch_worker_thread3 + 114,
12 libsystem_pthread.dylib 0x000000010191f7da _pthread_wqthread + 1299,
13 libsystem_pthread.dylib 0x000000010191f2b5 start_wqthread + 13
)
答案 0 :(得分:0)
大脑融化 - 等待应该
dispatch_semaphore_wait(s, dispatch_time(DISPATCH_TIME_NOW, 15.0 * NSEC_PER_SEC));