NSBlockOperation
NSBlockOperation *op1 = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@"1--%@",[NSThread currentThread]);
}];
NSBlockOperation *op2 = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@"2--%@",[NSThread currentThread]);
}];
NSBlockOperation *op3 = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@"3--%@",[NSThread currentThread]);
}];
[op1start];
[op2start];
[op3start];
在上述情况中,是不会开启子线程的,看图一打印结果
图一如果对 op3追加三个任务
[op3addExecutionBlock:^{
NSLog(@"4--%@",[NSThread currentThread]);
}];
[op3addExecutionBlock:^{
NSLog(@"5--%@",[NSThread currentThread]);
}];
[op3addExecutionBlock:^{
NSLog(@"6--%@",[NSThread currentThread]);
}];
此时在看打印结果
图二可以从图二中看出来,追加了三个任务后,确实开了子线程,但是这个三个子线程不一定就是4,5,6的子线程,需要注意.