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

条件变量(condition variable) #8

Open
wly0311 opened this issue Aug 15, 2024 · 0 comments
Open

条件变量(condition variable) #8

wly0311 opened this issue Aug 15, 2024 · 0 comments

Comments

@wly0311
Copy link

wly0311 commented Aug 15, 2024

1、条件变量那一章的第一个例子,如果step2和step3都在wait函数中阻塞,然后step1发送notify_one,但是唤醒的是step3,step3检查条件不满足,不能继续执行。然后又没有新的notify去触发step2。导致程序step2、step3阻塞不能继续执行。

2、如果在某些调度的情况下,当step1设置step1_done_完毕后,没有cout<<1之前,step2被调度执行,并且能执行完毕,由于它能被执行完毕,所以可能先输出2,然后在分两种情况
1)如果step3被调度并执行完,无论step3是否在wait函数中阻塞,都先输出3,然后输出1。即231
2)如果step1被调度,那么先输出1,最后是3。即213

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