02 2021 档案

摘要:由于NSTimer依赖于RunLoop,如果RunLoop的任务过于繁重,导致RunLoop执行一圈的时间不确定,可能回到NSTimer的 不准时,如果你需要高精度的定时器,那么GCD的定时器会符合你的需求,使用代码如下: // 创建定时器 dispatch_source_t timer = dis 阅读全文
posted @ 2021-02-27 11:34 木子沉雨 阅读(346) 评论(0) 推荐(0)
摘要:对于以下代码: @property (strong, nonatomic) NSTimer *timer; self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerTes 阅读全文
posted @ 2021-02-25 21:45 木子沉雨 阅读(218) 评论(0) 推荐(0)
摘要:iOS中读写安全方案 读写锁区别于线程锁,读写锁允许多个线程去读,但是去写的时候保证只有一个在写 pthread_rwlock // 初始化锁 pthread_rwlock_init(&_lock, NULL); // 加读锁 pthread_rwlock_rdlock(&_lock); // 尝试 阅读全文
posted @ 2021-02-25 20:38 木子沉雨 阅读(493) 评论(0) 推荐(0)
摘要:OSSpinLock OSSpinLock叫做"自旋锁",等待锁的线程会处于忙等状态,一直占用着cpu资源。由于可能会出现优先级反转的问题,是个不安全锁。在iOS10苹果已经不推荐使用了 优先级反转问题 如果等待锁的线程优先级较高,它会一直占用着CPU资源,优先级低的线程就无法释放 使用的时候需要导 阅读全文
posted @ 2021-02-24 21:18 木子沉雨 阅读(458) 评论(0) 推荐(0)
摘要:对于如下代码的,它的打印结果是什么 NSThread *thread = [[NSThread alloc] initWithBlock:^{ NSLog(@"1"); }]; [thread start]; [self performSelector:@selector(testhaha) onT 阅读全文
posted @ 2021-02-24 00:02 木子沉雨 阅读(95) 评论(0) 推荐(0)
摘要:对于如下的代码,打印结果是什么 dispatch_queue_t queue = dispatch_get_global_queue(0, 0); dispatch_async(queue, ^{ NSLog(@"1"); [self performSelector:@selector(testha 阅读全文
posted @ 2021-02-23 23:33 木子沉雨 阅读(162) 评论(0) 推荐(0)
摘要:RunLoop四个主要主要组成 Source0 触摸事件处理、performSelector:onThread: Source1 基于Port的线程间通信、系统事件的捕捉 Timers NSTimer、performSelector:withObject:afterDelay Observers 用 阅读全文
posted @ 2021-02-22 22:01 木子沉雨 阅读(154) 评论(0) 推荐(0)
摘要:什么是RunLoop runloop是运行循环,在程序运行过程中循环做一些事情 RunLoop应用范畴 定时器、PerformSelector、GCD 事件响应、手势识别、界面刷新、网络请求、自动释放池 获取RunLoop对象 iOS中有2套API来访问和使用RunLoop,分别是NSRunLoop 阅读全文
posted @ 2021-02-22 21:28 木子沉雨 阅读(180) 评论(0) 推荐(0)