BMChineseSort icon indicating copy to clipboard operation
BMChineseSort copied to clipboard

Semaphore object deallocated while in use Abort Cause 1 报错

Open shaobinbin0621 opened this issue 6 years ago • 1 comments

谷歌了下, ` semaphore = dispatch_semaphore_create(1);

//异步执行
dispatch_async(dispatch_get_global_queue(0, 0), ^{
    //将数据 转换为 BMChineseSortModel
    NSMutableArray *sortModelArray = [NSMutableArray arrayWithCapacity:0];
    [objectArray enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        BMChineseSortModel *model = [self getModelWithObj:obj key:key];
        if (model) {
            //对 数组的插入操作 上锁
            dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
                [sortModelArray addObject:model];
            dispatch_semaphore_signal(semaphore);
        }
    }];`

系统判断sema是否被使用的标志为sema被销毁时的值是否与初始化的值相同

shaobinbin0621 avatar Sep 11 '19 05:09 shaobinbin0621

解决了吗,我也遇到相同问题

zhoumingwu avatar Feb 16 '23 10:02 zhoumingwu