关于子线程中代码是否执行完毕

如下面代码所示,在text1 方法中又开辟了新的线程来执行for循环,但我想在for循环执行完毕后在执行text2,请问应该怎么操作

  • (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"%s",__func__); NSBlockOperation *ope1 = [NSBlockOperation blockOperationWithBlock:^{ [self text1]; }]; NSBlockOperation *ope2 = [NSBlockOperation blockOperationWithBlock:^{ [self text2]; }]; [ope2 addDependency:ope1]; [self.queue addOperation:ope1]; [self.queue addOperation:ope2];

}

  • (void)text1{
    dispatch_queue_t queue = dispatch_queue_create("111", NULL);
    dispatch_async(queue, ^{
    [self forCircle];
    });
    }

  • (void)forCircle{
    int a = 10000000;
    for (int i = 0; i < a; ++i) {
    //sleep(0.5);
    if (i == a - 1) {
    self.done = YES;
    }
    }
    }

  • (void)text2{
    if (self.queue.operations.count == 1) {
    if (self.done == YES) {
    NSLog(@"2222");
    }
    }

}


你用sem信号量来进行同步等