Defined in <stlab/concurrency/serial_queue.hpp>
template <typename E>
class serial_queue

An executor wrapper that causes enqueued tasks to be run serially.

Member types

Member type Definition
executor_t E

Member Functions

(constructor) Constructs a serial_queue
(destructor) Default-destructs a serial_queue

Constructs an executor from the serial queue

Passes the task to the serial_queue for scheduling and execution

Example 1

#include <iostream>
#include <thread>
#include <string>

#include <stlab/concurrency/default_executor.hpp>
#include <stlab/concurrency/serial_queue.hpp>

using namespace std;
using namespace stlab;

serial_queue_t ioq(default_executor);

void say_hello(string to_whom) {
    ioq.executor()([_whom = move(to_whom)](){
        cout << "Hello, " << _whom << "!\n";
    });
}

int main(int, char**) {
    say_hello("fella");
    say_hello("chief");
    say_hello("pal");
    say_hello("world");

    auto done = ioq([]{});

    while (!done.get_try()) { }
}

/*
    Result:

        Hello, fella!
        Hello, chief!
        Hello, pal!
        Hello, world!
*/