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

距离工程化还差一个cond #2

Open
yyzybb537 opened this issue Mar 21, 2019 · 4 comments
Open

距离工程化还差一个cond #2

yyzybb537 opened this issue Mar 21, 2019 · 4 comments

Comments

@yyzybb537
Copy link

如果队列为空,while (try read); 是一个会把cpu core吃满的操作,在实际工程中适用范围很小。

此处需要一个std::condition_variable来等待,引入condition又会有新的问题,不是使用者直接引入就能解决的,应该还是需要wait-free队列处理好这个事情。

@MengRao
Copy link
Owner

MengRao commented Mar 21, 2019

不一定要占满cpu忙等,可以做其他事或yield让出cpu

@yyzybb537
Copy link
Author

yield的效果也是不如cond好,虽然避免了单个cpu吃满的情况,但是yield的线程多了,对系统的负担也是挺重的,是一种无谓的浪费

@yyzybb537
Copy link
Author

也不一定要cond,但至少要让用户可以嵌入一个通知机制。
比如要传递数据给epoll网络线程时,就要能把处于epoll_wait状态的线程唤醒起来做事情

@ylovecj
Copy link

ylovecj commented May 6, 2019

@yyzybb537 如果队列为空,协程释放占用CPU, 如果用cond的话 一般怎么使用, 有示例的一些代码吗?

如果使用yield, 这个可以切换到当前线程的其他协程处理么?

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

3 participants