Shows how to use xtd::collections::concurrent::concurrent_queue class.
#include <xtd/xtd>
class example {
public:
static auto main() {
for (auto i = 0; i < 10000; ++i)
auto result = 0;
if (!cq.try_peek(result))
else if (result != 0)
auto outer_sum = 0;
auto action = [&cq, &outer_sum] {
auto local_sum = 0;
auto local_value = 0;
while (cq.try_dequeue(local_value)) local_sum += local_value;
interlocked::add(outer_sum, local_sum);
};
parallel::invoke(action, action, action, action);
}
};
Represents a thread-safe first in-first out (FIFO) collection.
Definition concurrent_queue.hpp:34
virtual auto enqueue(const_reference item) -> void
Adds an item to the end of the xtd::collections::concurrent::concurrent_queue <type_t>.
Definition concurrent_queue.hpp:136
static auto write_line() -> void
Writes the current line terminator to the standard output stream using the specified format informati...
#define startup_(...)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:152
Provides several thread-safe collection classes that should be used in place of the corresponding typ...
Definition concurrent_bag.hpp:20