OC 线程操作2 - NSThread
方法1 :直接创建 alloc init
- (void)createNSThread111{
/*
参数1: (nonnull id) 目标对象 self
参数2:(nonnull SEL) 方法选择器 ,调用的方法
参数3:(nullable id) 前面调用方法需要传递的参数 nil *
//1.创建线程 NSThread *thread= [[NSThread alloc] initWithTarget:self selector:@selector(run:) object:@"abc"];
//2.开启线程 [thread start]; } - (void)run:(NSString *)pama{ NSLog(@"---fun---%@", [NSThread currentThread]); }
打印结果: 2018-06-22 14:10:57.529875+0800 线程操作[6518:200227] ---fun---<NSThread: 0x608000265e40>{number = 3, name = (null)}--abc
方法2. 分离子线程 ,自动启动线程 detach [NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"分离子线程"];
打印结果 : 2018-06-22 14:10:57.530121+0800 线程操作[6518:200228] ---fun---<NSThread: 0x608000265f40>{number = 4, name = (null)}--分离子线程
方法3.开启后台一个线程 performSelectorInBackground
[self performSelectorInBackground:@selector(run:) withObject:@"开启一后台线程"];
打印结果 : 2018-06-22 14:10:57.530164+0800 线程操作[6518:200229] ---fun---<NSThread: 0x608000265dc0>{number = 5, name = (null)}
--开启一后台线程
第一种 设置线程阻塞,阻塞2秒
+ (void)sleepForTimeInterval:(NSTimeInterval)ti;// 线程停止 几秒
[NSThread sleepForTimeInterval:2.0];
第二种设置线程阻塞2,以当前时间为基准阻塞4秒
+ (void)sleepUntilDate:(NSDate *)date;
//控制线程状态
NSDate *date=[NSDate dateWithTimeIntervalSinceNow:4.0];
[NSThread sleepUntilDate:date];
// 线程退出
+ (void)exit;
他人总结 OS开发多线程篇—线程的状态 链接 :https://www.cnblogs.com/wendingding/p/3807184.html
OC 线程操作2 - NSThread的更多相关文章
- OC 线程操作 - GCD队列组
1.队列组两种使用方法2.队列组等待 wait /** 新方法 队列组一般用在在异步操作,在主线程写队列组毫无任何作用 */ - (void)GCD_Group_new_group___notify{ ...
- OC 线程操作 - GCD快速迭代
- (void)forDemo{ //全都是在主线程操作的 ; i<; i++) { NSLog(@"--%@", [NSThread currentThread]); } ...
- OC 线程操作3 - NSOperation
#import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...
- OC 线程操作 - GCD使用 -同步函数,异步函数,串行队列,并发队列
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ // GCD 开几条线程并不是我们 ...
- OC 线程操作 - GCD使用 -线程通讯, 延迟函数和一次性代码
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ // [self downImag ...
- OC 线程操作1 - pthread
#import "ViewController.h" #import <pthread.h> //1.需要包含这个头文件 @interface ViewControll ...
- OC 线程操作3 - NSOperation 实现线程间通信
#import "ViewController.h" @interface ViewController () /** 图片 */ @property (weak, nonatom ...
- OC 线程操作 - GCD使用 - 栅栏函数
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //同步函数无需栅栏函数 //栅栏 ...
- OC线程操作-GCD介绍
1. GCD介绍 1.11.2 1.3 异步具备开启能力但是不是 一定可以开启 1.4 1.5 67. 8.
随机推荐
- ros建立ospf邻居的条件
Two routers do not become neighbors unless the following conditions are met. Two way communication b ...
- [UE4]单映射:TMap容器,字典表
一.TMap是什么 TMap是UE4中的一种关联容器,每个键都关联着一个值,形成了单映射关系.因此你可以通过键名来快速查找到值.此外,单映射要求每个键都是唯一的. 二.创建和填充单映射 如果你想创建一 ...
- javascript callee和caller
arguments的主要用途是保存参数,但是他还有callee属性. 一:callee指向arguments对象的函数. 示例一: function calture(num) {//阶乘计算 if ( ...
- Python的collections模块中namedtuple结构使用示例
namedtuple顾名思义,就是名字+元组的数据结构,下面就来看一下Python的collections模块中namedtuple结构使用示例 namedtuple 就是命名的 tuple,比较 ...
- Tomcat 支持的Java 版本和兼容性总结
https://tomcat.apache.org/whichversion.html 最新最全的Tomcat 支持的Java版本对照,即兼容性一览表: Servlet Spec JSP Spec ...
- Mysql-两表的连接,copy表,select的各种用法
-- 连接:外连接,内连接 两个表之间 外连接:right join left join -- left join 左标为主 一般以值少的为主 select * from table1 left ...
- 35. CentOS-6.3安装拼音输入法
安装方法: su root yum install "@Chinese Support" // 安装中文输入法 exit 装好后,在“系统-->首选项”就会看到有“ ...
- js 断点调试
- 可视化库-seaborn-回归分析绘图(第五天)
1. sns.regplot() 和 sns.lmplot() 绘制回归曲线 import numpy as np import pandas as pd from scipy import stat ...
- Others-接口集成方式
1. 异步通信方式可分为不互锁.半互锁和全互锁三种类型: a.不互锁方式 主模块发出请求信号后,不等待接到从模块的回答信号,而是经过一段时间.确认从模块已收到请求信号后,便撤消其请求信号:从设备接到请 ...