// singleton, you can try to do so with a weak_ptr. Avoid this when
// possible but the inability to lock the weak pointer can be a
// signal that the vault has been destroyed.
- static std::weak_ptr<T> get_weak() {
+ static std::weak_ptr<T>
+ get_weak() __attribute__ ((__deprecated__("Replaced by try_get"))) {
return getEntry().get_weak();
}
SingletonCreationError<ErrorConstructor> error_once_singleton;
// first time should error out
- EXPECT_THROW(error_once_singleton.get_weak().lock(), std::runtime_error);
+ EXPECT_THROW(error_once_singleton.try_get(), std::runtime_error);
// second time it'll work fine
- error_once_singleton.get_weak().lock();
+ error_once_singleton.try_get();
SUCCEED();
}
std::vector<std::thread> ts;
for (size_t i = 0; i < 100; ++i) {
ts.emplace_back([&]() {
- slowpoke_singleton.get_weak().lock();
+ slowpoke_singleton.try_get();
});
}