Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
login,register等函数变成多线程安全的 - 10 分login的登录计时器改成基于 chrono 的 - 5 分shared_mutex区分读和写 - 10 分lock_guard系列符合 RAII 思想 - 5 分并通过
main()函数中的基本测试。users以及has_login,分别用shared_mutex进行互斥保护。用shared_mutex是为了实现读写锁。并且为了提高性能,尽量最小化互斥区代码,在适当的时候unlock释放锁std::chrono::steady_clock::now()获取时间,并用std::chrono::duration转换为秒数shared_mutex,见第一点unique_lock以及shared_lock实现读写锁,其实用lock_guard性能会更高ThreadPool中定义std::vector<std::future<void>>数据成员,每次create调用时,调用async将返回值push到vector中。future对象调用wait。do_queryuser中,不能直接users.at(username),否则可能会报out_of_range异常。