- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(run:) object:@"universe"];
[thread start];
[thread release];
[NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"yuzhou"];
[self performSelectorInBackground:@selector(run:) withObject:@"nsobject thread"];
NSOperationQueue *oprationQueue = [[NSOperationQueue alloc] init];
[oprationQueue addOperationWithBlock:^{
NSLog(@"oprationQueue");
}];
[oprationQueue release];
NSOperationQueue *oprationQueue1 = [[NSOperationQueue alloc] init];
oprationQueue1.maxConcurrentOperationCount = 1;
NSInvocationOperation *invation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(run:) object:@"invation"];
[oprationQueue1 addOperation:invation];
[invation release];
NSInvocationOperation *invation2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(run2:) object:@"invocation2"];
invation2.queuePriority = NSOperationQueuePriorityHigh;
[oprationQueue1 addOperation:invation2];
[invation2 release];
[oprationQueue1 release];
[self performSelectorOnMainThread:@selector(onMain) withObject:self waitUntilDone:YES];
dispatch_queue_t queue = dispatch_queue_create("name", NULL);
dispatch_async(queue, ^{
NSLog(@"GCD多线程");
dispatch_sync(dispatch_get_main_queue(), ^{
Boolean isMain = [NSThread isMainThread];
if (isMain) {
NSLog(@"GCD主线程");
}
});
});
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (void)onMain
{
Boolean b = [NSThread isMainThread];
if (b) {
NSLog(@"onMain;;%d",b);
}
}
- (void) run:(NSString*)str
{
NSLog(@"多线程运行:::%@",str);
}
- (void) run2:(NSString*)str
{
NSLog(@"多线程运行:::%@",str);
}