tbb::parallel_while< Body > Class Template Reference
Algorithms

Parallel iteration over a stream, with optional addition of more work. More...

`#include <parallel_while.h>`

Inheritance diagram for tbb::parallel_while< Body >:
Collaboration diagram for tbb::parallel_while< Body >:

## Public Types

typedef Body::argument_type | value_type
| Type of items. More...

## Public Member Functions

| parallel_while ()
| Construct empty non-running parallel while. More...
| ~parallel_while ()
| Destructor cleans up data members before returning. More...
template<typename Stream >
void | run (Stream &stream, const Body &body)
| Apply body.apply to each item in the stream. More...
void | add (const value_type &item)
| Add a work item while running. More...

## Private Attributes

const Body * | my_body
empty_task * | my_barrier

## Additional Inherited Members

Private Member Functions inherited from tbb::internal::no_copy
| no_copy (const no_copy &)=delete
| no_copy ()=default

## Detailed Description

### template<typename Body>
class tbb::parallel_while< Body >

Parallel iteration over a stream, with optional addition of more work.

The Body b has the requirement:
"b(v)"
"b.argument_type"
where v is an argument_type

Definition at line 29 of file parallel_while.h.

## Member Typedef Documentation

## value_type

template<typename Body >

typedef Body::argument_type tbb::parallel_while< Body >::value_type

Type of items.

Definition at line 142 of file parallel_while.h.

## Constructor & Destructor Documentation

## parallel_while()

template<typename Body >

tbb::parallel_while< Body >::parallel_while | ( |  | ) |

inline

Construct empty non-running parallel while.

Definition at line 131 of file parallel_while.h.

: my_body(NULL), my_barrier(NULL) {}

## ~parallel_while()

template<typename Body >

tbb::parallel_while< Body >::~parallel_while | ( |  | ) |

inline

Destructor cleans up data members before returning.

Definition at line 134 of file parallel_while.h.

{
if( my_barrier ) {
my_barrier->destroy(*my_barrier);
my_barrier = NULL;
}
}

References tbb::parallel_while< Body >::my_barrier.

## Member Function Documentation

## add()

template<typename Body >

void tbb::parallel_while< Body >::add | ( | const value_type & | item | ) |

Add a work item while running.

Should be executed only by body.apply or a thread spawned therefrom.

Definition at line 176 of file parallel_while.h.

{
__TBB_ASSERT(my_barrier,"attempt to add to parallel_while that is not running");
typedef internal::while_iteration_task<Body> iteration_type;
iteration_type& i = *new( task::allocate_additional_child_of(*my_barrier) ) iteration_type(item,*my_body);
task::self().spawn( i );
}

References __TBB_ASSERT, and tbb::task::self().

Here is the call graph for this function:

## run()

template<typename Body >
template<typename Stream >

void tbb::parallel_while< Body >::run | ( | Stream & | stream,
|  | const Body & | body
| ) |  |

Apply body.apply to each item in the stream.

A Stream s has the requirements
"S::value_type"
"s.pop_if_present(value) is convertible to bool

Definition at line 162 of file parallel_while.h.

{
using namespace internal;
empty_task& barrier = *new( task::allocate_root() ) empty_task();
my_body = &body;
my_barrier = &barrier;
my_barrier->set_ref_count(2);
while_task<Stream,Body>& w = *new( my_barrier->allocate_child() ) while_task<Stream,Body>( stream, body, barrier );
my_barrier->spawn_and_wait_for_all(w);
my_barrier->destroy(*my_barrier);
my_barrier = NULL;
my_body = NULL;
}

References tbb::task::allocate_root(), tbb::task::set_ref_count(), and tbb::task::spawn_and_wait_for_all().

Here is the call graph for this function:

## Member Data Documentation

## my_barrier

template<typename Body >

empty_task* tbb::parallel_while< Body >::my_barrier

private

Definition at line 157 of file parallel_while.h.

Referenced by tbb::parallel_while< Body >::~parallel_while().

## my_body

template<typename Body >

const Body* tbb::parallel_while< Body >::my_body

private

Definition at line 156 of file parallel_while.h.

The documentation for this class was generated from the following file:

- parallel_while.h

tbb::task::set_ref_count
void set_ref_count(int count)
Set reference count.
Definition: task.h:750
internal
Definition: _flow_graph_async_msg_impl.h:24
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb::task::allocate_child
internal::allocate_child_proxy & allocate_child()
Returns proxy for overloaded new that allocates a child task of *this.
Definition: task.h:670
tbb::task::spawn_and_wait_for_all
void spawn_and_wait_for_all(task &child)
Similar to spawn followed by wait_for_all, but more efficient.
Definition: task.h:789
tbb::parallel_while::my_body
const Body * my_body
Definition: parallel_while.h:156
tbb::task::self
static task &__TBB_EXPORTED_FUNC self()
The innermost task being executed or destroyed by the current thread at the moment.
Definition: task.cpp:201
tbb::task::allocate_root
static internal::allocate_root_proxy allocate_root()
Returns proxy for overloaded new that allocates a root task.
Definition: task.h:652
tbb::parallel_while::my_barrier
empty_task * my_barrier
Definition: parallel_while.h:157

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.