线程之间的通信
来源:互联网 发布:网络电视看不见翡翠台 编辑:程序博客网 时间:2024/05/16 10:35
<p>线程间通信:在1个进程中,线程往往不是孤立存在的,多个线程之间需要经常进行通信</p><p> </p><p>线程间通信的体现</p><p>1个线程传递数据给另1个线程</p><p>在1个线程中执行完特定任务后,转到另1个线程继续执行任务</p>#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. SEL sel[3] = { @selector(nsthread), @selector(gcd), @selector(operationQueue) }; for (NSInteger i = 0; i < 3; i++) { NSThread *th = [[NSThread alloc]initWithTarget:self selector:sel[i] object:nil]; [th start]; }}#pragma mark -线程通信(主线程)--(void)nsthread{ //NSThread 获取主线程的方法 [self performSelectorOnMainThread:@selector(finish) withObject:self waitUntilDone:NO]; //下面这条语句还是子线程 !!!! NSLog(@"nsthread%@",[NSThread currentThread]);}-(void)gcd{ //GCD获取主线程的方法 dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"gcd%@",[NSThread currentThread]); [self finish]; });}-(void)operationQueue{ //NSOperationQueue 获取主队列 NSOperationQueue *mainQueue = [NSOperationQueue mainQueue]; [mainQueue addOperationWithBlock:^{ NSLog(@"mainQueue%@",[NSThread currentThread]); [self finish]; }];}-(void)finish{ NSLog(@"完成!!!!!!");}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
0 0
- 线程之间的通信
- 线程之间的通信
- 线程之间的通信
- 线程之间的通信
- 线程之间的通信
- 线程之间的通信
- 线程之间的通信
- 线程之间的通信
- 线程之间的通信
- 线程之间的通信
- 线程之间的通信
- 线程之间的通信
- 线程之间的通信
- 线程之间的通信
- 线程之间的通信
- java线程之间的通信
- 多线程-线程之间的通信
- linux线程之间的通信
- CodeVS2599 电路的稳定性
- STL学习之map
- k个最大的m段子数组和
- Tomcat默认访问路径的配置
- Iterator抽取迭代基类/Memento抽取备忘管理类/Interpreter终结非终结解释
- 线程之间的通信
- [bzoj1093][ZJOI2007]最大半连通子图
- html5应用缓存
- list的独有sort
- 欢迎使用CSDN-markdown编辑器
- Linux战地日记——ls命令、注释、管道线和后台命令
- AVL树旋转的一点理解
- getView()的原理
- 01关于正则表达式(第一则)