Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::call_once

 

std::call_once is a C++11 standard function to call another function exactly one time.

 

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: CppCall_once.pro

 

#-------------------------------------------------
#
# Project created by QtCreator 2012-02-11T06:20:36
#
#-------------------------------------------------
QT       += core
QT       -= gui
QMAKE_CXXFLAGS += -std=c++0x
TARGET = CppCall_once
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
SOURCES += main.cpp

 

 

 

 

 

main.cpp

 

#include <iostream>
#include <thread>

void f() { std::cout << "Hello world\n"; }

int main()
{
  std::once_flag flag;
  std::call_once(flag,&f);
  std::call_once(flag,&f);
  std::call_once(flag,&f);
}

 

Screen output:

 

Hello world

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml