Thread-Safe Initialization

What problem does std::call_once solve?

std::once_flag flag;
std::shared_ptr<Resource> resource;

void init() {
    std::call_once(flag, []() {
        resource = std::make_shared<Resource>();
    });
}
A

It defers initialization until the Resource is first accessed

B

It ensures the lambda runs on a specific thread

C

It ensures the initialization runs exactly once even if multiple threads call init() concurrently

D

It makes the Resource object immutable after initialization