[#BSLMT_ONCE_DO]
= BSLMT&lowbar;ONCE&lowbar;DO
:mrdocs:

Bracket a block of code so it executes only once in a multithreaded program&period;

== Synopsis

Declared in `&lt;bslmt&lowbar;once&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
#define BSLMT&lowbar;ONCE&lowbar;DO

----

== Description

This macro provides a simple control construct to bracket a piece of code that should only be executed once during the course of a multithreaded program&period; Usage&colon; &grave; BSLMT&lowbar;ONCE&lowbar;DO &lcub; &sol;&ast; one&hyphen;time code goes here &ast;&sol; &rcub; &grave; Leaving a `BSLMT&lowbar;ONCE&lowbar;DO` construct via `break`, `continue`, or `return` will put the construct in a &quot;done&quot; state (unless `BSLMT&lowbar;ONCE&lowbar;CANCEL` has been called) and will unblock all threads waiting to enter the one&hyphen;time region&period; Note that a `break` or `continue` within the one&hyphen;time code will terminate only the `BSLMT&lowbar;ONCE&lowbar;DO` construct, not any surrounding loop or switch statement&period; Due to a bug in the Microsoft Visual C&plus;&plus; 2003 compiler, the behavior is undefined if an exception is thrown from within this construct and is not caught within the same construct&period; Only one call to `BSLMT&lowbar;ONCE&lowbar;DO` may appear on a single source&hyphen;code line in any code block&period;


[.small]#Created with https://www.mrdocs.com[MrDocs]#
