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

lambda 的参数是怎么传递的呀 #25

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

Conversation

miyanyan
Copy link

修改

  • users 和 login 添加了shared_mutex,在只读的部分采用 shared_lock
  • 使用 chrono::seconds 记录登录的时间戳time_since_epoch,进行时间计算
  • 使用线程池,创建几个线程,每个线程都是死循环,每次调用create时把要执行的函数放到任务队列里,通知可用的线程去执行。
  • 现程池的析构函数里要 停止死循环, 等待任务队列都执行完。

问题

lambda函数传到void create(std::function<void()> start)里时直接start()是能打印出user.school这些信息的,但是我把它放到了队列里之后再在线程里job = m_jobs.front(); job();貌似就把std::function<void()>的参数给丢掉了呢,打印出来的user.school就变成了空字符串……
image

{
for (size_t i = 0; i < m_poll_size; ++i) {
m_workers.emplace_back(
[&]() {
Copy link
Contributor

Choose a reason for hiding this comment

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

可能改成[=]就可以了。

@miyanyan
Copy link
Author

miyanyan commented Jan 31, 2022 via email

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.

2 participants