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

refactor wait_group #342

Merged
merged 3 commits into from
Jun 26, 2024
Merged

refactor wait_group #342

merged 3 commits into from
Jun 26, 2024

Conversation

ChrisCatCP
Copy link
Contributor

重构了wait_group,基本就是参考了golang的实现

@zhengshuxin
Copy link
Member

add 为何要 box->push多次,而在wait里却pop一次?与原实现方式是相反的。

@ChrisCatCP
Copy link
Contributor Author

用来唤醒多个等待者,之前的实现方式不支持多等待,并且wait_group无法进行复用,并且还有些其他的问题。。

@zhengshuxin
Copy link
Member

Go里的WaitGroup不是要等待Add里加的次数吗?比如创建10个协程,Add(10),然后 Wait() 实际上是待这个10个协程都调用了Done后Wait 才返回。

@ChrisCatCP
Copy link
Contributor Author

是的,但是他那个支持复用的,并且可以有多个地方wait

@ChrisCatCP ChrisCatCP closed this Jun 25, 2024
@ChrisCatCP ChrisCatCP reopened this Jun 25, 2024
@zhengshuxin
Copy link
Member

如果想要象go里的一样,通过Add(10),然后最后通过一个Wait() 完成等待过程,你的实现似乎无法完成这项功能。

@ChrisCatCP
Copy link
Contributor Author

ChrisCatCP commented Jun 26, 2024

可以啊,我跑过那个sample了

@zhengshuxin
Copy link
Member

能否添加些注释,把设计思想简单介绍一下?

@ChrisCatCP
Copy link
Contributor Author

额,就是copy了下golang的实现😂

@ChrisCatCP
Copy link
Contributor Author

中午我加一下注释

@ChrisCatCP
Copy link
Contributor Author

已经加上注释了

@zhengshuxin
Copy link
Member

已经加上注释了

从注释很难理解设计思想呀 :)

@ChrisCatCP
Copy link
Contributor Author

已经加上注释了

从注释很难理解设计思想呀 :)

state高低32位记录count和waiter,add增加count,done减少count,count为0会唤醒所有等待的线程或协程,wait会增加waiter的数量并且阻塞等待唤醒,大概就是这么个意思。

@zhengshuxin zhengshuxin merged commit fc6a460 into acl-dev:master Jun 26, 2024
@zhengshuxin
Copy link
Member

已合并,谢谢。

@ChrisCatCP
Copy link
Contributor Author

好的😊

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

Successfully merging this pull request may close these issues.

None yet

2 participants