Skip to content

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

Description

@ShowHandAce

大神你好.拜读代码和博客,写的都非常详细,对我帮助很大.十分感谢~
现在有个小问题:代码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];
        }
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions