std call once std once flag

suggest change

std::call_once runs a function once for a given std::once_flag, even when several threads call it. If the function returns, later calls do nothing. If it throws, the exception propagates and the flag is not set, so another call may try again. std::call_once throws std::system_error when the once-mechanism itself cannot run the function.

Used in conjunction with std::once_flag.

#include <mutex>
#include <iostream>

std::once_flag flag;
void do_something(){
      std::call_once(flag, [](){std::cout << "Happens once" << std::endl;});
    
      std::cout << "Happens every time" << std::endl;
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents