Consider a large-scale application where multiple threads often access shared objects concurrently. Which smart pointer can be used to ensure that an object is deleted only when the last pointer to it is out of scope, considering thread safety?
- raw pointer
- shared_ptr
- unique_ptr
- weak_ptr
shared_ptr is thread-safe in terms of its reference counting mechanism, ensuring that the object is safely managed across multiple threads and deleted only when the last pointer to it goes out of scope.
Loading...
Related Quiz
- When is a copy constructor called in a C++ program?
- Which type of function cannot be virtual in C++?
- To read an entire string from a file, instead of a single character, use the _______ function.
- The minimum possible value of a variable of type short int is _______.
- How would you implement a loop that executes a specific number of times and uses an iterator?