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

伪唤醒可能导致资源浪费 #43

Open
HandsomeGiao opened this issue Oct 24, 2024 · 1 comment
Open

伪唤醒可能导致资源浪费 #43

HandsomeGiao opened this issue Oct 24, 2024 · 1 comment

Comments

@HandsomeGiao
Copy link

if (is_waiting) {
				std::unique_lock<std::mutex> locker(lok);
				task_done_workers++;
				task_done_cv.notify_one();
				thread_cv.wait(locker);
}

这是在workbranch.hpp里面的mission函数的一段代码,这段代码最后的 thread_cv.wait(locker) 应该改为 thread_wait(locker,!is_waiting) 吗?否则伪唤醒可能让一个没有任务的线程一直执行yield()函数,导致资源浪费.

@CodingHanYa
Copy link
Owner

确实存在伪唤醒,但是问题在于多一次循环后task_done_workers++导致计数不准。

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