本网页所有文字内容由 imapbox邮箱云存储,邮箱网盘, iurlBox网页地址收藏管理器 下载并得到。
ImapBox 邮箱网盘 工具地址: https://www.imapbox.com/download/ImapBox.5.5.1_Build20141205_CHS_Bit32.exe
PC6下载站地址:PC6下载站分流下载
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox 网页视频 工具地址: https://www.imapbox.com/download/ImovieBox4.7.0_Build20141115_CHS.exe
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
– (void)updateLabel:(NSNumber *)aObject
{
self.displayLabel.text = [aObject stringValue];
NSLog(@"is duo xiancheng = %@",[[NSNumber numberWithBool:[NSThread isMultiThreaded]] stringValue]);
}
int n = 200000000;
– (void)compute:(NSNumber *)aObject
{
double sum = 0;
for (int a = aObject.intValue; a < n ; a++)
{
sum = sum + a;
// [self print:a];
}
[self performSelectorOnMainThread:@selector(updateLabel:) withObject:[NSNumber numberWithDouble:sum] waitUntilDone:NO];
}
– (void)thread1
{
[NSThread detachNewThreadSelector:@selector(compute:) toTarget:self withObject:[NSNumber numberWithInt:i]];
}
– (void)thread2
{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//group
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, queue, ^{
double sum = 0;
for (int a = i; a < n ; a++)
{
sum = sum + a;
}
NSLog(@"queue 1 = %f",sum);
});
dispatch_barrier_async(queue, ^{
double sum = 0;
for (int a = i; a < n ; a++)
{
sum = sum + a;
}
NSLog(@"barrier = %f",sum);
});
dispatch_group_async(group, queue, ^{
double sum = 0;
for (int a = i; a < n ; a++)
{
sum = sum + a;
}
NSLog(@"queue 2 = %f",sum);
});
dispatch_group_async(group, queue, ^{
double sum = 0;
for (int a = i; a < n ; a++)
{
sum = sum + a;
}
NSLog(@"queue 3 = %f",sum);
});
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
self.displayLabel.text = @"all done";
});
//async
// dispatch_async(queue, ^{
// double sum = 0;
// for (int a = i; a < n ; a++)
// {
// sum = sum + a;
//// [self print:a];
// }
// dispatch_async(dispatch_get_main_queue(), ^{
// self.displayLabel.text = [NSString stringWithFormat:@"%f",sum];
// NSLog(@"is duo xiancheng = %@",[[NSNumber numberWithBool:[NSThread isMultiThreaded]] stringValue]);
// });
// });
//
dispatch_async(queue, ^{
double sum = 0;
for (int a = i; a < n ; a++)
{
sum = sum + a;
}
NSLog(@"barrier queue 1 = %f",sum);
});
dispatch_async(queue, ^{
double sum = 0;
for (int a = i; a < n ; a++)
{
sum = sum + a;
}
NSLog(@"barrier = %f",sum);
});
dispatch_async(queue, ^{
double sum = 0;
for (int a = i; a < n ; a++)
{
sum = sum + a;
}
NSLog(@"barrier queue 2 = %f",sum);
});
dispatch_async(queue, ^{
double sum = 0;
for (int a = i; a < n ; a++)
{
sum = sum + a;
}
NSLog(@"barrier queue 3 = %f",sum);
});
}
– (void)thread3
{
NSMethodSignature *sig = [self methodSignatureForSelector:@selector(compute:)];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig];
[invocation setTarget:self];
[invocation setSelector:@selector(compute:)];
NSNumber *num = [NSNumber numberWithInt:i];
[invocation setArgument:&num atIndex:2];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithInvocation:invocation];
//[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(compute:) object:];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperation:operation];
}
– (void)thread4
{
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(compute:) object:[NSNumber numberWithInt:i]];
[thread start];
}
– (void)thread5
{
[self performSelectorInBackground:@selector(compute:) withObject:[NSNumber numberWithInt:i]];
}
阅读和此文章类似的: 程序员专区