Make `shared_state` thread-safe