pThread多线程demo
程序员文章站
2024-01-07 09:46:34
#import "ViewController.h" #import @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIButto... ......
#import "ViewController.h" #import <pthread.h> @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(100, 100, 100, 30); [btn setTitle:@"pThread" forState:UIControlStateNormal]; [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [btn addTarget:self action:@selector(clickPThread) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; } - (void)clickPThread { NSLog(@"我在主线程中执行!!!"); pthread_t pthread; pthread_create(&pthread, NULL, run, NULL); } // C语言写法 void *run(void *data) { NSLog(@"我在子线程中执行!!!"); for (int i = 1; i < 10; i++) { NSLog(@"%d", i); sleep(1); } return NULL; }
推荐阅读
-
极光推送按照官网例子写的demo报错"Response timeout"但手机客户端还是能收到推送消息,而且是多条?
-
求个php+ajax+easyUI datagrid的简略完整的demo
-
(用微信扫的静态链接二维码)微信native支付模式官方提供的demo文件中的几个bug修正,nativedemo
-
【JavaSE】多线程Part2(12)
-
Angular Elements 组件在非Angular 页面中使用的DEMO
-
Java多线程面试问答
-
javascript是多线程语言吗
-
flask开启多线程的具体方法
-
Babylonjs 官网demo预览图合集整理 带说明
-
实现多线程的两种传统方式