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

关于线程池这一章的问题 #3

Open
Chen-Xuming opened this issue Sep 4, 2022 · 0 comments
Open

关于线程池这一章的问题 #3

Chen-Xuming opened this issue Sep 4, 2022 · 0 comments

Comments

@Chen-Xuming
Copy link

“往线程池添加任务会增加任务队列的竞争,lock-free 队列可以避免这点但存在乒乓缓存的问题。为此需要把任务队列拆分为线程独立的本地队列和全局队列,当线程队列无任务时就去全局队列取任务”

在这一小节中,submit函数中的local_queue永远是nullptr,原因如下:
local_queue指针在worker_thread中赋值,woker_thread运行在子线程,而submit函数是在main线程中调用的,二者不是在同一线程,所以二者的local_queue根本不是同一个。

所以这段代码无法达到想要的目的。

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