线程通信
来源:互联网 发布:我的巨星男佣网络剧 编辑:程序博客网 时间:2024/06/14 11:34
// 线程通信, 主-子, 子-主 // 线程之间的相互跳转 // 主线程 - > 子线程 // 子线程 - > 主线程 // 1. dispatch_async(dispatch_get_main_queue(), ^{ // 回到主线程 // block 任务 }); // 2. [self performSelectorOnMainThread:@selector(mainThreadAction) withObject:nil waitUntilDone:YES]; // 子线程 - > 子线程 // 创建一个线程对象 NSThread *createThread = [[NSThread alloc]init]; createThread.name = @"other"; // 进入子线程 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self performSelector:@selector(otherThreadAction) onThread:createThread withObject:nil waitUntilDone:YES]; });}- (void) mainThreadAction { NSLog(@"回到主线程");}// 验证已经跳转到 other 的子线程中的方法- (void)otherThreadAction { NSLog(@"---%d",[NSThread isMainThread]);}
0 0
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- 线程通信
- hdu2563 统计问题(递推)
- Linux学习笔记:用fdisk工具分区,swap分区的管理
- MFC中数据类型转换的一些心得
- 2本地搭建服务器
- HDU——1215七夕节(因数和)
- 线程通信
- 从0开始学习OC程序-第1天
- 个人对多线程的认识NSThread
- C#Winform中运用DevExpress提供的ChartControl控件绘制折线统计图
- TCP三次握手及释放连接详解
- JSP 的 page 编译指令的属性session 的默认值 true
- NYOJ 34 韩信点兵
- 环奇
- 12306线程管理