33
Execution control library
[exec]
33.12
Execution contexts
[exec.ctx]
33.12.1
execution::run_
loop
[exec.run.loop]
33.12.1.1
General
[exec.run.loop.general]
1
#
A
run_
loop
is an execution resource on which work can be scheduled
.
It maintains a thread-safe first-in-first-out queue of work
.
Its
run
member function removes elements from the queue and executes them in a loop on the thread of execution that calls
run
.
2
#
A
run_
loop
instance has an associated
count
that corresponds to the number of work items that are in its queue
.
Additionally, a
run_
loop
instance has an associated state that can be one of
starting
,
running
,
finishing
, or
finished
.
3
#
Concurrent invocations of the member functions of
run_
loop
other than
run
and its destructor do not introduce data races
.
The member functions
pop-front
,
push-back
, and
finish
execute atomically
.
4
#
Recommended practice
: Implementations should use an intrusive queue of operation states to hold the work units to make scheduling allocation-free
.
namespace
std
::
execution
{
class
run_loop
{
//
[exec.
run.
loop.
types]
, associated types
class
run-loop-scheduler
;
//
exposition only
class
run-loop-sender
;
//
exposition only
struct
run-loop-opstate-base
{
//
exposition only
virtual
void
execute
(
)
=
0
;
//
exposition only
run_loop
*
loop
;
//
exposition only
run
-
loop
-
opstate
-
base
*
next
;
//
exposition only
}
;
template
<
class
Rcvr
>
using
run-loop-opstate
=
unspecified
;
//
exposition only
//
[exec.
run.
loop.
members]
, member functions
run-loop-opstate-base
*
pop-front
(
)
;
//
exposition only
void
push-back
(
run-loop-opstate-base
*
)
;
//
exposition only
public
:
//
[exec.
run.
loop.
ctor]
, constructor and destructor
run_loop
(
)
noexcept
; run_loop
(
run_loop
&
&
)
=
delete
;
~
run_loop
(
)
;
//
[exec.
run.
loop.
members]
, member functions
run-loop-scheduler
get_scheduler
(
)
;
void
run
(
)
;
void
finish
(
)
;
}
;
}