HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 创建具有相同名称的串行队列的2个对象共享相同的队列大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
不确定的行为,因为我怀疑我陷入僵局,

我有一个具有多个对象的类 – 每个对象创建一个有相名称的队列.我不知道GCD是否在对象之间重复使用相同的队列,或者如果他们只是共享相同的名称.

例如

@interface MyClass

-(void)doSomeWork
@property (nonatomic,strong) dispatch_queue_t myQueue;

@end

@implementation MyClass

-(id)init
{
  self = [super init];
  self.myQueue = dispatch_queue_create("MyQueue",DISPATCH_QUEUE_seriaL);
  return self;
}

-(void)doSomeWork
{
  dispatch_async(self.myQueue,^{
    // some long running work
  });
}

@end


@interface someClassWhichCreatesALotOfObjects

@end


@implementation someClassWhichCreatesALotOfObjects

-(void)someMethod
{
  for(int i = 0; i < 10000; i++)
  {
    MyClass *object = [MyClass new];
    [object doSomeWork]; // are these running in serial to each other or are each offset to the queue their object has created? Can't understand from the debugger
  }
}
@end

解决方法

正如苹果公司的文件所述,标签是:

它被用作提示,没有更多.

编辑

以下是使用共享队列的代码.

+ (dispatch_queue_t)sharedQueue
{
    static dispatch_queue_t sharedQueue;
    static dispatch_once_t onCEToken;
    dispatch_once(&onCEToken,^{
        sharedQueue = dispatch_queue_create("MyQueue",null);
    });
    return sharedQueue;
}

大佬总结

以上是大佬教程为你收集整理的ios – 创建具有相同名称的串行队列的2个对象共享相同的队列全部内容,希望文章能够帮你解决ios – 创建具有相同名称的串行队列的2个对象共享相同的队列所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。