OC中多线程的创建方法

方法一:
NSThread *t = [[NSThread alloc] initWithTarget:self selector:@selector(mutableThread) object:nil];
方法二:
[NSThread detachNewThreadSelector:@selector(mutableThread) toTarget:self withObject:nil];
方法三:
[self performSelectorInBackground:@selector(mutableThread) withObject:nil];
方法四:多线程blog创建
NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
//会开启一个多线程
[operationQueue addOperationWithBlock:^{
for(int i = 0; i < 50 ;i++)
{
NSLog(@"多线程:%d",i);
}
}];
方法五:
//相当于是一个线程池
NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
operationQueue.maxConcurrentOperationCount = 1;//设置并发数
//创建线程
NSInvocationOperation *opertion1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(thread1) object:nil];
//设置线程的优先级
[opertion1 setQueuePriority:NSOperationQueuePriorityVeryLow];
//创建另一个线程
NSInvocationOperation *opertion2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(thread2) object:nil];
[opertion2 setQueuePriority:NSOperationQueuePriorityHigh];
方法六:
dispatch_queue_t queue = dispatch_queue_create("test",NULL);
dispatch_async(queue,^{
for(int i=0;i<50;i++)
{
NSLog(@"多线程:%d",i);
});
上一篇:Centos 6.x XFS 数据盘扩容示例


下一篇:C# asp.net常见编译|运行错误