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

2.1.1 post和traverse示例问题 #22

Open
ghost opened this issue Sep 16, 2018 · 1 comment
Open

2.1.1 post和traverse示例问题 #22

ghost opened this issue Sep 16, 2018 · 1 comment

Comments

@ghost
Copy link

ghost commented Sep 16, 2018

你好,买了你的书,不错啊!
但有个地方不太明白,你在2.1.1使用了shared_ptr::unique来断言g_foos是否为FooList的唯一引用,如果不是唯一引用,则重置。如下:
void post(const Foo& f)
{
printf("post\n");
getlock locker(mutex);
if (!g_foos.unique())
{
g_foos.reset(new FooList(*g_foos));
printf("copy the whole list\n");
}
assert(g_foos.unique());
g_foos->push_back(f);
}
但是,我在https://zh.cppreference.com/w/cpp/memory/shared_ptr/unique这个文档中看到一段话:
“此函数于 C++17 中被弃用并于 C++20 中移除,因为 use_count 在多线程环境中只是估计”。
请问如果我参考了你的解决方案,应用在项目中,后续是否有问题?
谢谢!

@FlyHuss
Copy link

FlyHuss commented Sep 19, 2018

shared_ptr::use_count了解一下

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

No branches or pull requests

1 participant