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

信号量在这里有什么作用? #1

Closed
baxiang opened this issue Jun 26, 2017 · 1 comment
Closed

信号量在这里有什么作用? #1

baxiang opened this issue Jun 26, 2017 · 1 comment
Labels

Comments

@baxiang
Copy link

baxiang commented Jun 26, 2017

override func main() {

    while self.isCancelled == false {
        self.isMainThreadBlock = true
        DispatchQueue.main.async {
            self.isMainThreadBlock = false
            self.semaphore.signal()
        }
        
        Thread.sleep(forTimeInterval: self.threshold)
        if self.isMainThreadBlock  {
            self.handler?()
        }
        
        self.semaphore.wait(timeout: DispatchTime.distantFuture)
    }

按照我自己的代码思维: 当前变量isMainThreadBlock = YES, 让当前线程休眠0.4秒,看主线程是否修改了当前的变量isMainThreadBlock 值是否函数回调。但是我看不明白这个信号量在这个中所要做的事情是什么?

@zixun
Copy link
Owner

zixun commented Aug 8, 2017

用来控制ping主线程的,你debug下就明白了。或者看《iOS监控编程》中卡顿监控篇

@zixun zixun closed this as completed Aug 8, 2017
@zixun zixun added the question label Aug 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants