一、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. 关于log4net 生成多个文件夹的解决方案。

    解决方案: 在append节点内加入: <param name="lockingModel" type="log4net.Appender.FileAppender ...

  2. LeetCode_Spiral Matrix

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  3. shell下有操作json对象的库

    http://kernelpanic.im/blog/2012/03/08/shell-manipulate-json/ Json.org推荐了两个:Jshon和JSON.sh 其中JSON.sh是完 ...

  4. 单线多拨,傻瓜式openwrt单线多拨叠加速率教程

    http://bbs.pceva.com.cn/thread-98362-1-1.html

  5. java生成字符串md5函数类(javaSE)

    //实现生成MD5值 import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.B ...

  6. hdu 5430 Reflect (数学推导题)

    Problem Description We send a light from one point on a mirror material circle,it reflects N times a ...

  7. Hibernate(四)——缓存策略+lazy

    Hibernate作为和数据库数据打交道的框架,自然会设计到操作数据的效率问题,而对于一些频繁操作的数据,缓存策略就是提高其性能一种重要手段,而Hibernate框架是支持缓存的,而且支持一级和二级两 ...

  8. PC-常见问题-清除浮动

    常用:.clear{clear:both;height:0px;overflow:hidden;}>最优浮动闭合方案(这是我们推荐的): .clearfix:after{content:&quo ...

  9. Spark常用函数讲解之Action操作

    摘要: RDD:弹性分布式数据集,是一种特殊集合 ‚ 支持多种来源 ‚ 有容错机制 ‚ 可以被缓存 ‚ 支持并行操作,一个RDD代表一个分区里的数据集RDD有两种操作算子:         Trans ...

  10. Highcharts 非常实用的Javascript统计图

    Highcharts 官网: http://www.highcharts.com Highcharts 官网示例:http://www.highcharts.com/demo/ Highcharts ...