浅析iOS应用开发中线程间的通信与线程安全问题

线程间的通信

 

简单说明

线程间通信:在1个进程中,线程往往不是孤立存在的,多个线程之间需要经常进行通信

 

线程间通信的体现

1个线程传递数据给另1个线程

在1个线程中执行完特定任务后,转到另1个线程继续执行任务

 

线程间通信常用方法

- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait;

- (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait;


线程间通信示例 – 图片下载

//

//  YYViewController.m

//  06-NSThread04-线程间通信

//

//  Created by apple on 14-6-23.

//  Copyright (c) 2014年 itcase. All rights reserved.

//

#import "YYViewController.h"

@interface YYViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *iconView;

@end

以上是 浅析iOS应用开发中线程间的通信与线程安全问题 的全部内容, 来源链接: utcz.com/z/337585.html

回到顶部