Skip to content

bulk::queue

Defined in header <bulk/messages.hpp>.

template <typename T, typename... Ts>
class queue;

bulk::queue is an inbox for receiving messages passed by processors.

Template parameters

  • T - the type of the message content
  • Ts - a parameter pack, optionally containing extra message content

Note: content components of array type, e.g. T[] are also supported. They are represented by a std::vector<T>.

Member types

  • message_type: the underlying type used by the messages. Equal to:
    • T if sizeof...(Ts) == 0,
    • std::tuple<T, Ts...> otherwise.
  • iterator: the type of the iterator used for the local inbox

Member functions

(constructor) constructs the queue
(deconstructor) deconstructs the queue
operator= assign the queue
Communication
operator() obtain a sender to a remote queue
Container
begin obtain an iterator to the start
end obtain an iterator to the end
size obtain the number of messages
empty check if the queue is empty
World access
world returns the world of the queue

Nested classes

  • sender: an object providing syntactic sugar for sending messages

Example

#include "bulk/bulk.hpp"

#include "set_backend.hpp"

int main() {
    environment env;

    env.spawn(env.available_processors(), [](bulk::world& world) {
        auto raw_queue = bulk::queue<int>(world);
        raw_queue(world.next_processor()).send(1);
        raw_queue(world.next_processor()).send(2);
        raw_queue(world.next_processor()).send(123);

        auto tuple_queue = bulk::queue<int, int, int>(world);
        tuple_queue(world.next_processor()).send(1, 2, 3);
        tuple_queue(world.next_processor()).send(4, 5, 6);

        world.sync();

        // read queue
        for (auto x : raw_queue) {
            world.log("the first queue received a message: %d", x);
        }

        for (auto [i, j, k] : tuple_queue) {
            world.log("the second queue received a tuple: (%d, %d, %d)",
                      i, j, k);
        }
    });

    return 0;
}