测试代码段如下,
dispatch_semaphore_t sema = dispatch_semaphore_create(-1);
dispatch_semaphore_signal(sema);
运行结果:崩溃
如图
原因见苹果文档对于参数的描述:
dispatch_semaphore_t dispatch_semaphore_create(long value);
...
Parameters: value The starting value for the semaphore. Do not pass a value less than zero.
在参数为负时候,此函数会返回为nil,c函数dispatch_semaphore_signal操作nil就会出现崩溃
网友评论