为什么[NSThread exit]会报错:Thread 3 signal SIGABRT? 有完整 救命代码
#import "AppDelegate.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
//创建一个线程队列
NSOperationQueue *theradQueue=[[NSOperationQueue alloc] init];
//设置最大同时多少线程
[theradQueue setMaxConcurrentOperationCount:1];
//添加线程操作对像
NSInvocationOperation *op =[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(mutableThread:) object:@"test"];
//设置纯种优先级别
op.queuePriority=NSOperationQueuePriorityHigh;
[theradQueue addOperation:op];
for(int i=0; i<=100; i++)
{NSLog(@"主线程 %d",i);
}
return YES;
}
-(void )mutableThread:(NSString *)t
{
// NSLog(@"mutableThread %@",t);
for(int i=0; i<=100; i++)
{
NSLog(@"子线程 %d",i);
}
//跳到主线程进行执行 waitUntilDone 英 [?n?t?l] 美 [?n?t?l] prep.到…为止; 在…以前 conj.到…为止,在…以前; 直到…才 是否要等待方法执行完成后再继续执行
[self performSelectorOnMainThread:@selector(mutableThreadCompleter:) withObject:@"OK" waitUntilDone:YES];
//暂停1秒
[NSThread sleepForTimeInterval:1];
NSLog(@"子线程 完成");
//退出线程
[NSThread exit]; //? 这里报错:Thread 3 signal SIGABRT
}
-(void) mutableThreadCompleter:(NSString *)t
{
BOOL isMain =[NSThread isMainThread];
NSLog(@"线程完成 %@ 主线程%@",t,isMain?@"YES":@"NO");
}
@end