| Home | Libraries | People | FAQ | More

## Function call_once

boost::call_once — The call_once function and `once_flag` type (statically initialized to BOOST_ONCE_INIT) can be used to run a routine exactly once. This can be used to initialize data in a thread-safe manner.

## Synopsis

     call_once(void (*func)() func, once_flag& flag);

## Description

Example usage is as follows:

    //Example usage:
    boost::once_flag once = BOOST_ONCE_INIT;

    void init()
    {
        //...
    }

    void thread_proc()
    {
        boost::call_once(&init, once);
    }

Requires: | The function `func` shall not throw exceptions.
Effects: | As if (in an atomic fashion): `if (flag == BOOST_ONCE_INIT) func();`
Postconditions: | `flag != BOOST_ONCE_INIT`

| Copyright © 2001-2003 William E. Kempf