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

HW05 by Ytterbium #24

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

HW05 by Ytterbium #24

wants to merge 2 commits into from

Conversation

Mwsxy
Copy link

@Mwsxy Mwsxy commented Jan 23, 2022

完成了基本的作业要求,没有参加内卷:(

  1. 使用chrono中的时间戳类型替换C语言的计时方式。
  2. 为users和has_login两个全局变量添加读写锁保护。
  3. 使用unique_lock和shared_lock完成RAII式上锁。
  4. 为tpool添加了链表结构保存维持后台线程运行不退出。
  5. 为线程池添加解构函数,遍历链表join,确保所有线程都结束后再退出。

Copy link
Contributor

@archibate archibate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • login, register 等函数变成多线程安全的 - 7/10 分
  • login 的登录计时器改成基于 chrono 的 - 5/5 分
  • 能利用 shared_mutex 区分读和写 - 10/10 分
  • lock_guard 系列符合 RAII 思想 - 5/5 分
  • 让 ThreadPool::create 创建的线程保持后台运行不要退出 - 15/15 分
  • 等待 tpool 中所有线程都结束后再退出 - 4/5 分
  • 能够在 PR 描述中用自己的话解释 20/25 分
  • 代码格式规范、能够跨平台 5/5 分
  • 有自己独特的创新点 8/20 分

使用了链表很有创意!实际上用 vector 遍历,最后再 clear 一下就可以了 :)

Comment on lines +46 to +47
}
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两个锁的区域之间 has_login 有可能会被改动哦,需要第二个锁区域二次判断,或者合并为一个写锁的锁区域。

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.

3 participants