...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
A channel for messages.
template< typename Executor, typename Traits, typename... Signatures> class basic_concurrent_channel
Name |
Description |
---|---|
Rebinds the channel type to another executor. |
|
The type of the executor associated with the channel. |
|
The traits type associated with the channel. |
Name |
Description |
---|---|
Asynchronously receive a message. |
|
Asynchronously send a message. |
|
basic_concurrent_channel [constructor] |
Construct a basic_concurrent_channel. |
Cancel all asynchronous operations waiting on the channel. |
|
Get the capacity of the channel's buffer. |
|
Close the channel. |
|
Get the executor associated with the object. |
|
Determine whether the channel is open. |
|
Move-assign a basic_concurrent_channel from another. |
|
Determine whether a message can be received without blocking. |
|
Reset the channel to its initial state. |
|
Try to receive a message without blocking. |
|
Try to send a message without blocking. |
|
Try to send a number of messages without blocking. |
|
~basic_concurrent_channel [destructor] |
Destructor. |
The experimental::basic_concurrent_channel
class template
is used for sending messages between different parts of the same application.
A message is defined as a collection of arguments to
be passed to a completion handler, and the set of messages supported by a
channel is specified by its Traits
and Signatures...
template parameters. Messages may be sent and received using asynchronous
or non-blocking synchronous operations.
Unless customising the traits, applications will typically use the experimental::concurrent_channel
alias template. For
example:
void send_loop(int i, steady_timer& timer, concurrent_channel<void(error_code, int)>& ch) { if (i < 10) { timer.expires_after(chrono::seconds(1)); timer.async_wait( [i, &timer, &ch](error_code error) { if (!error) { ch.async_send(error_code(), i, [i, &timer, &ch](error_code error) { if (!error) { send_loop(i + 1, timer, ch); } }); } }); } else { ch.close(); } } void receive_loop(concurent_channel<void(error_code, int)>& ch) { ch.async_receive( [&ch](error_code error, int i) { if (!error) { std::cout << "Received " << i << "\n"; receive_loop(ch); } }); }
Distinct objects: Safe.
Shared objects: Safe.
The experimental::basic_concurrent_channel
class template
is thread-safe, and would typically be used for passing messages between
application code that run on different threads. Consider using experimental::basic_channel
, and its alias template
experimental::channel
, to pass messages between code
running in a single thread or on the same strand.
Header: boost/asio/experimental/basic_concurrent_channel.hpp
Convenience header: None