多线程 NSThread 了解
// DYFViewController.m// 623-02-pthread//// Created by dyf on 14-6-23.// Copyright (c) 2014年 ___FULLUSERNAME___. All rights reserved.//#import "DYFViewController.h"#import <pthread.h>@interface DYFViewController ()@end@implementation DYFViewController//// c语言函数//void *run(void *data)//{// // 1.获取当前的线程// NSThread *cThread = [NSThread currentThread];// // // 2.打印线程// NSLog(@"%@", cThread);// // // 3.h耗时操作// for (int i = 0; i < 9999; i++) {// NSLog(@"%@", cThread);// }//// return NULL;//}- (IBAction)btnOnClick { // 1.获取当前的线程 NSThread *cthread = [NSThread currentThread]; NSThread *mt = [NSThread mainThread]; // 2.打印线程 NSLog(@"%@", cthread); NSLog(@"%@", mt); // 3.执行一线耗时的操作 : 创建一套子线程 [self threadCreate3]; }- (void)run:(NSString *)parma{// [NSThread threadPriority];// // [NSThread setThreadPriority:0.55]; // 取值0-1,默认0.5 for (int i = 0; i < 9999; i++) { NSLog(@"%@---------%@", [NSThread currentThread], parma); }}- (void)threadCreate5{ // 分离出的子线程 [NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"2222222"];}- (void)threadCreate4{ // 分离出的子线程 [NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"2222222"];}/** * NSThread创建方式3:隐世线程创建,并且直接(自动)启动 */- (void)threadCreate3{ [self performSelectorInBackground:@selector(run:) withObject:@"333333"];}/** * 创建方式2:创建完线程后自动启动 */- (void)threadCreate2{ // 分离出的子线程 [NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"2222222"];}/** * 创建方式1:①先创建初始化子线程②再启动 */- (void)threadCreate{ NSThread *thread1 = [[NSThread alloc] initWithTarget:self selector:@selector(run:) object:@"heheh"]; thread1.name = @"thread1"; // 开启线程 [thread1 start]; NSThread *thread2 = [[NSThread alloc] initWithTarget:self selector:@selector(run:) object:@"heheh"]; thread2.name = @"thread2"; // 开启线程 [thread2 start]; NSThread *thread3 = [[NSThread alloc] initWithTarget:self selector:@selector(run:) object:@"heheh"]; thread3.name = @"33"; // 开启线程 [thread3 start];}@end利用NSThread在开发中也不常用,了解即可
多线程 NSThread 了解的更多相关文章
- iOS多线程 NSThread/GCD/NSOperationQueue
无论是GCD,NSOperationQueue或是NSThread, 都没有线程安全 在需要同步的时候需要使用NSLock或者它的子类进行加锁同步 "] UTF8String], DISPA ...
- 多线程NSThread基本用法
#import "ViewController.h" @interface ViewController () @end @implementation ViewContr ...
- [iOS]深入浅出 iOS 之多线程 NSThread
OS 支持多个层次的多线程 编程,层次越高的抽象程度越高,使用起来也越方便,也是苹果最推荐使用的方法. 下面简要说明这三种不同范式: Thread 是这三种范式里面相对轻量级的,但也是使用起 ...
- 多线程 -- NSThread
NSThread NSThread 一个NSThread对象就代表一条线程 创建线程的几种方式 alloc/init // 1.创建线程 NJThread *thread = [[NJThread a ...
- [iOS 多线程 & 网络 - 1.1] - 多线程NSThread
A.NSThread的基本使用 1.创建和启动线程 一个NSThread对象就代表一条线程创建.启动线程NSThread *thread = [[NSThread alloc] initWithTar ...
- 多线程 NSThread GCD
ios多线程实现种类 NSThread NSOperationQueue NSObject GCD *************** 1.NSThread //线程 第一种 NSThread *thre ...
- iOS多线程NSThread和GCD
在iOS中啊 其实有多种方法实现多线程 这里只记录两个比较常用的 或者说我比较常用的 一个就是BSThread 另一个就是一听名字就比较霸气的妇孺皆知的GCD 先说一下NSThread吧 这个方式 ...
- iOS 多线程NSThread理解与场景示例
NSThread是相对GCD和NSOperationQuene而言,比较轻量级的一种多线程处理方式. 但同时,它的弊端就是需要自己管理线程的生命周期,以及线程同步:而另外两种不需要自己管理. 常见方法 ...
- 九、使用多线程——NSThread,GCD和NSOperation
概述 早上起床,你先打开洗衣机,然后用热水把泡面泡上,接着打开电脑开启一天的码农生活.其中“洗衣服”.“泡泡面”和“码代码”3个任务(线程)同时进行,这就是多线程.网上有许多关于多线程的经典解释,此处 ...
- IOS 多线程 NSThread
一个正在运行的应用程序是一个进程,一个进程会默认开启一个主线程,但是在主线程中的操作是串行的,也就是当有多个任务同时需要完成的时候,是按照顺序一个个执行.因此,为了提高效率,会在进程中开启多个线程,每 ...
随机推荐
- [Phoenix] 七、如何使用自增ID
摘要: 在传统关系型数据库中设计主键时,自增ID经常被使用.不仅能够保证主键的唯一,同时也能简化业务层实现.Phoenix怎么使用自增ID,是我们这篇文章的重点. 在传统关系型数据库中设计主键时,自增 ...
- 在yum出问题的情况下安装某个rpm包的方法
1 核心命令 rpm -i 2 方法 centos镜像站去找到所有的rpm包. 安装这个rpm包,发现有一个依赖没有安装,就去下载安装.因为整体的包是有限的,因此终会收敛的. 比如安装rpmbuild ...
- define tensorflow and run it
import tensorflow as tf a, b, c, d, e = tf.constant(5, name='input_a'), tf.constant(6, name='input_b ...
- git文章列表
关于gitlab默认clone协议 Git实现从本地加入项目到远程仓库 翻翻git之---一个简单的标签控件 LabelView (随手发了两张小宝宝的玩耍照) id=1125" targe ...
- Linux就该这么学--命令集合7(管道命令符)
1.管道命令符“|”的作用是将前一个命令的标准输出当作后一个命令的标准输入,格式为:“命令A|命令B”. 找出被限制登录用户的命令是:grep "/sbin/nologin" /e ...
- ABAP抓取异常 try ,endtry.
DATA: O_CX TYPE REF TO CX_ROOT. TRY . MOVE LS_UPLOAD-MENGE TO LS_OUTPUT-MENGE. CATCH CX_ROOT INTO O_ ...
- linux shell执行远程计算机上的命令或者脚本(ssh)
大数据平台下经常建立设计多个节点的集群需要统一部署,这就设计到守护进程或者部署脚本在不同节点执行,如果能在master机器上,统一执行脚本,一次性启动整个集群的服务,感觉很nice.因为,分享如下内容 ...
- String StringBuffer StringBuilder 三者之间的区别
今天被公司骗去面试,好糟心...... 这个问题不管去哪里面试,基础问题基本上都会问到这个问题.网上好多大神都总结,这里自己也总结一下. 首先我们最开始学的就是String字符串常量,这里有行代码 S ...
- Codeforces Round #371 (Div. 2) C. Sonya and Queries —— 二进制压缩
题目链接:http://codeforces.com/contest/714/problem/C C. Sonya and Queries time limit per test 1 second m ...
- Linux下压缩某个文件夹命令
tar -zcvf /home/xahot.tar.gz /xahot tar -zcvf 打包后生成的文件名全路径 要打包的目录 例子:把/xahot文件夹打包后生成一个/home/xahot.ta ...