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

if (enable_steal_tasks) 的意义 #8

Open
Crowbar1024 opened this issue Feb 15, 2023 · 3 comments
Open

if (enable_steal_tasks) 的意义 #8

Crowbar1024 opened this issue Feb 15, 2023 · 3 comments

Comments

@Crowbar1024
Copy link

如果能执行到worker中的 if (enable_steal_tasks) 的代码块,意味着waiting=false,但这又意味着全部任务执行完了,这个时候从其他线程的工作队列拿任务的意义何在?不是全部任务已经没了吗?求懂哥解释

@CodingHanYa
Copy link
Owner

没有维护一个全局任务数,所以线程也无法知道其它线程是否还有任务,只能先去搜索。如果没搜索到,再通知CPU切换到其它线程执行。

@Crowbar1024
Copy link
Author

void waitForTasks() {
    for (int i = 0; i < thread_numb; ++i) {
        threads[i].waitTasksDone();
    }
    for (int i = 0; i < thread_numb; ++i) {
       threads[i].cleanWaitingFlag();
    }
}

对这段代码我的理解是:如果某个线程的waiting==false,那么该pond的所有线程的任务数已经为0了。那么怎么去偷窃呢?

@CodingHanYa
Copy link
Owner

我不太能理解你想表达的 { '_' }

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

2 participants