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

一个貌似重复判断的小问题 #11

Open
ShowHandAce opened this issue Aug 24, 2018 · 0 comments
Open

一个貌似重复判断的小问题 #11

ShowHandAce opened this issue Aug 24, 2018 · 0 comments

Comments

@ShowHandAce
Copy link

大神你好.拜读代码和博客,写的都非常详细,对我帮助很大.十分感谢~
现在有个小问题:代码173行和179行有两次主线程判断,能否解释一下为什么这样做?是有什么特殊的处理吗?
个人理解第一个主线程判断 return 掉以后,第二个判断应该是走不到的.
望解答~

if ([nsthread isMainThread]) {
    return (thread_t)main_thread_id;
}

for (int i = 0; i < count; ++i) {
    pthread_t pt = pthread_from_mach_thread_np(list[i]);
    if ([nsthread isMainThread]) {
        if (list[i] == main_thread_id) {
            return list[i];
        }
    }
    if (pt) {
        name[0] = '\0';
        pthread_getname_np(pt, name, sizeof name);
        if (!strcmp(name, [nsthread name].UTF8String)) {
            [nsthread setName:originName];
            return list[i];
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant