Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有关任务的执行思考? #4

Open
hulinSun opened this issue Aug 29, 2019 · 1 comment
Open

有关任务的执行思考? #4

hulinSun opened this issue Aug 29, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@hulinSun
Copy link

static void addRunLoopObserver() { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ taskSchedulers = [NSHashTable weakObjectsHashTable]; CFRunLoopObserverRef observer = CFRunLoopObserverCreate(CFAllocatorGetDefault(), kCFRunLoopBeforeWaiting | kCFRunLoopExit, true, 0xFFFFFF, runLoopObserverCallBack, NULL); CFRunLoopAddObserver(CFRunLoopGetMain(), observer, kCFRunLoopCommonModes); CFRelease(observer); }); }

利用runloop,将我们收敛的任务执行在runloop运行期间。但是注意到,永远是在main runloop 触发这些任务的执行的。假如,我在子线程中添加了任务,但是主线程卡住了。意味着主线程的runloop 不能够及时的触发状态回调而触发任务执行。而受到牵连的在子线程添加的任务不能够及时执行。这种情况子线程的任务执行情况反而依赖于主线程的卡顿情况.
主线程的卡顿,反而影响到了子线程的执行效率
如果主线程极端卡顿的情况下。多线程执行的优势就不存在了~

@indulgeIn
Copy link
Owner

你说的情况是存在的,不过一个正常的 APP 主线程一般不会长时间卡顿。
这算是一个可优化的地方,可以让用户指定任务调度的线程。

@indulgeIn indulgeIn added the enhancement New feature or request label Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants