为什么[NSThread exit]会报错:Thread 3 signal SIGABRT? 有完整 救命代码

javamy030 2013-11-29 12:12:30

#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


为什么[NSThread exit]会报错:Thread 3 signal SIGABRT? 有完整 救命代码

谢谢
...全文
304 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
RannieR 2013-12-02
  • 打赏
  • 举报
回复
NSOperationQueue里的操作在完成后会自动标记自身状态为完成后退出线程队列的,不需要你手动去强制退出。而且操作一旦开始也不能强制退出。再而且,NSThread跟操作不属于一类多线程概念= =
咸清 2013-11-30
  • 打赏
  • 举报
回复
基本概念都不清楚!回去看看书吧。
寂默有时 2013-11-29
  • 打赏
  • 举报
回复
换成return试下? 我的是C++ 用pthread_exit也是受到SIGABRT http://bbs.csdn.net/topics/390656401

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧