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

解决issue 906,完成对银行任务代码编写 #1039

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

breayhing
Copy link

利用condition对象

存钱时,将新的余额更新,然后使用notify_all()通知所有等待的线程,存钱操作已完成。
取钱操作:

取钱时,如果余额不足,线程会等待,直到有其他线程存钱,并调用notify_all()通知。
一旦余额足够,取钱操作将继续,更新余额。
多线程执行:

使用ThreadPoolExecutor创建5个存钱线程和5个取钱线程。
通过这种方式,可以保证在多个线程并发操作银行账户时,余额的更新是安全的,并且在余额不足时,取钱操作会等待,直到有足够的余额。

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.

1 participant