[exec.run.loop.members]

# 33 Execution control library [[exec]](./#exec)

## 33.12 Execution contexts [[exec.ctx]](exec.ctx#exec.run.loop.members)

### 33.12.1 execution​::​run_loop [[exec.run.loop]](exec.run.loop#members)

#### 33.12.1.4 Member functions [exec.run.loop.members]

[ð](#itemdecl:1)

`run-loop-opstate-base* pop-front();
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6514)

*Effects*: Blocks ([[defns.block]](defns.block "3.6 block")) until one of the following conditions is true:

- [(1.1)](#1.1)

*count* is 0 and *state* is *finishing*,
in which case *pop-front* sets *state* to *finished* and returns nullptr; or

- [(1.2)](#1.2)

*count* is greater than 0,
in which case an item is removed from the front of the queue,*count* is decremented by 1, and
the removed item is returned[.](#1.sentence-1)

[ð](#itemdecl:2)

`void push-back(run-loop-opstate-base* item);
`

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6535)

*Effects*: Adds item to the back of the queue and
increments *count* by 1[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6540)

*Synchronization*: This operation synchronizes with
the *pop-front* operation that obtains item[.](#3.sentence-1)

[ð](#lib:get_scheduler,run_loop)

`run-loop-scheduler get_scheduler();
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6552)

*Returns*: An instance of *run-loop-scheduler* that can be used to schedule work onto this run_loop instance[.](#4.sentence-1)

[ð](#lib:run,run_loop)

`void run();
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6564)

*Preconditions*: *state* is either *starting* or *finishing*[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6568)

*Effects*: If *state* is *starting*,
sets the *state* to *running*,
otherwise leaves *state* unchanged[.](#6.sentence-1)

Then, equivalent to:while (auto* op = *pop-front*()) { op->*execute*();}

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6580)

*Remarks*: When *state* changes, it does so without introducing data races[.](#7.sentence-1)

[ð](#lib:finish,run_loop)

`void finish();
`

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6591)

*Preconditions*: *state* is either *starting* or *running*[.](#8.sentence-1)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6595)

*Effects*: Changes *state* to *finishing*[.](#9.sentence-1)

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L6599)

*Synchronization*: finish synchronizes with the *pop-front* operation
that returns nullptr[.](#10.sentence-1)
