实现事件同步 - 信号量的坑

有问题代码:

  
   dispatch_async(self.queue_handleAppear, ^{
        dispatch_semaphore_wait(self.semphore_t, DISPATCH_TIME_FOREVER);
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"hhh任务:%@ 开始执行",message);
            [currentView makeToast:message duration:interval position:position withFinishBlock:^( BOOL completeRes) {
                if (completeRes) {
                    NSLog(@"hhh任务:%@ 结束执行",message);
                    dispatch_semaphore_signal(self.semphore_t);
                }
            }];
        });
    });
    
    注意: queue_handleAppear是串行队列

正确解决方式:

     dispatch_async(self.queue_handleAppear, ^{
        [self.condition lock];
        dispatch_async(dispatch_get_main_queue(), ^{
            [currentView makeToast:message duration:interval position:position withFinishBlock:^( BOOL completeRes) {
                if (completeRes) {
                    [self.condition unlock];
                }
            }];
        });
    })
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 12:04
毕业生招你惹你了,问一个发薪日来一句别看网上乱七八糟的你看哪个工作没有固定发薪日扭头就取消了面试就问了一句公司都是这个态度吗还搞上人身攻击了...
程序员小白条:呃呃呃,都还没面试,我都不会问这么细,何况通不通过,去不去都另说,你没实力和学历的话,在外面就这样,说实话没直接已读不回就不错了,浪费时间基本上
点赞 评论 收藏
分享
缒梦&独舞:这家公司是这样的,去年给我实习offer了,不过也是面着玩儿的,他周六还要去做公益志愿活动
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务