一、NSThread 线程间的通讯

 - (void)demoAboutNSThread
 {
     NSLog(@"demoAboutNSThread %@", [NSThread currentThread]);
     NSThread * thread = [[NSThread alloc] initWithTarget:self selector:@selector(longTimeOperation) object:nil];
     [thread start];
 }

 - (void)longTimeOperation
 {
      NSLog(@"longTimeOperation %@", [NSThread currentThread]);
     [self performSelectorOnMainThread:@selector(mainThreadOperation) withObject:nil waitUntilDone:NO];
 }

 - (void)mainThreadOperation
 {
     NSLog(@"mainThreadOperation %@",[NSThread currentThread]);
 }

二、GCD 线程间通讯

 - (void)dispatchDemo
 {
     NSLog(@" start %@",[NSThread currentThread]);

     dispatch_async(dispatch_get_global_queue(, ), ^{
         NSLog(@" 耗时从左 %@",[NSThread currentThread]);

         dispatch_sync(dispatch_get_main_queue(), ^{
             NSLog(@" 回到主线程 %@", [NSThread currentThread]);
         });

     });

     NSLog(@"end %@",[NSThread currentThread]);
 }

三、NSOperation 线程间的通讯

 - (void)demoAboutNSOperation
 {
    NSOperation * block =  [NSBlockOperation blockOperationWithBlock:^{
         NSLog(@"block %@",[NSThread currentThread]);
     }];

     [self.queue addOperation:block];

     [self.queue addOperationWithBlock:^{
         NSLog(@"耗时操作 %@",[NSThread currentThread]);
         [[NSOperationQueue mainQueue] addOperationWithBlock:^{
             NSLog(@" mainQueue %@",[NSThread currentThread]);
         }];
     }];

 }

iOS开发多线程-线程间通讯的更多相关文章

  1. iOS开发之线程间的MachPort通信与子线程中的Notification转发

    如题,今天的博客我们就来记录一下iOS开发中使用MachPort来实现线程间的通信,然后使用该知识点来转发子线程中所发出的Notification.简单的说,MachPort的工作方式其实是将NSMa ...

  2. iOS开发多线程篇—线程间的通信

    iOS开发多线程篇—线程间的通信 一.简单说明 线程间通信:在1个进程中,线程往往不是孤立存在的,多个线程之间需要经常进行通信 线程间通信的体现 1个线程传递数据给另1个线程 在1个线程中执行完特定任 ...

  3. iOS开发多线程篇 04 —线程间的通信

    iOS开发多线程篇—线程间的通信 一.简单说明 线程间通信:在1个进程中,线程往往不是孤立存在的,多个线程之间需要经常进行通信 线程间通信的体现 1个线程传递数据给另1个线程 在1个线程中执行完特定任 ...

  4. java 并发性和多线程 -- 读感 (二 线程间通讯,共享内存的机制)

    参考文章:http://ifeve.com/java-concurrency-thread-directory/ 其中的竞态,线程安全,内存模型,线程间的通信,java ThreadLocal类小节部 ...

  5. iOS开发多线程篇—线程安全

    iOS开发多线程篇—线程安全 一.多线程的安全隐患 资源共享 1块资源可能会被多个线程共享,也就是多个线程可能会访问同一块资源 比如多个线程访问同一个对象.同一个变量.同一个文件 当多个线程访问同一块 ...

  6. Java:多线程<三>死锁、线程间通讯

    死锁: 同步嵌套同步,而且使用的锁不是同一把锁时就可能出现死锁 class Test implements Runnable { private boolean flag; Test(boolean ...

  7. iOS开发多线程篇—创建线程

    iOS开发多线程篇—创建线程 一.创建和启动线程简单说明 一个NSThread对象就代表一条线程 创建.启动线程 (1) NSThread *thread = [[NSThread alloc] in ...

  8. iOS开发多线程篇—线程的状态

    iOS开发多线程篇—线程的状态 一.简单介绍 线程的创建: self.thread=[[NSThread alloc]initWithTarget:self selector:@selector(te ...

  9. 黑马程序员——JAVA基础之多线程的线程间通讯等

    ------- android培训.java培训.期待与您交流! ---------- 线程间通讯: 其实就是多个线程在操作同一个资源,但是动作不同. wait(); 在其他线程调用此对象的notif ...

随机推荐

  1. a标签# 和javascript:;的区别

    最近遇到一个问题,解决了记录下来. <body style="height:10000px;"> <span style="top:3000px;pos ...

  2. NSArray和NSMutableArray相互转换, 以及常用方法-备

    有时候项目中NSArray和NSMutableArray需要相互转化,下面给出相关代码1.NSArray 1.1 转化:NSMutableArray 1 NSMutableArray *mutable ...

  3. SVN取消记住密码

    百度上面找的,SVN取消记录密码的方法: 找到这个文件夹首先需要在文件夹选项里面,显示所有的文件和文件夹,不能隐藏. SVN取消记住用户名的方法 打开C:\Documents and Settings ...

  4. hdu 1245 Saving James Bond

    http://acm.hdu.edu.cn/showproblem.php?pid=1245 #include <cstdio> #include <cstring> #inc ...

  5. 模拟IIC总线汇编程序软件包

    一.概述 为了非常方便地对 I2C 从器件进行快速的.正确的读写操作,我们为此而设计出虚拟 I2C 总线操作平台软件包.本软件包是主方式下的虚拟 I2C 总线软件包,只要用户给子程序提供几个主要的参数 ...

  6. 使用opencv传中文文件崩溃

    这个问题经过我的调试发现:   程序是在 while (*at && !isdigit(*at)) at++;   这个语句时crash的,但是跟进去是isdigit的问题,因为变量a ...

  7. 转:helloworld:一个完整的WCF案例

    原文地址:http://blog.csdn.net/mane_yao/article/details/5852845 WCF的ABC: A代表Address-where(对象在哪里)B代表Bindin ...

  8. 2014.11.12模拟赛【最小公倍数】| vijos1047最小公倍数

    最小公倍数(lcm.c/.cpp/.pas) 题目描述 给定两个正整数,求他们的最小公倍数. 样例输入 28 12 样例输出 84 数据范围 对于40%数据:1<=a,b<=10^9 对于 ...

  9. Integer to English Words 解答

    Question Convert a non-negative integer to its english words representation. Given input is guarante ...

  10. hdu3410-Passing the Message(RMQ,感觉我写的有点多此一举。。。其实可以用单调栈)

    What a sunny day! Let’s go picnic and have barbecue! Today, all kids in “Sun Flower” kindergarten ar ...