All challenges
Multiple ChoiceIntermediate 45s

shared_ptr thread safety scope

Which operations on a single `std::shared_ptr` instance are thread-safe without external locking?
Options
  1. 1All of them, including reset() and assignment, are fully thread-safe because the count is atomic and uses a lock.
  2. 2Only the destructor is thread-safe, because it is the single member that internally acquires the control-block lock.
  3. 3Only copying is thread-safe, because the atomic retain makes the read of the pointer value itself race-free and orderly.
  4. 4None of the mutating ones: concurrent read/write of the same shared_ptr object is a data race, though distinct instances sharing an object are safe.

Think you can answer under pressure?

Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.

Play this in a 3-minute battle