Skip to content
木头云 edited this page Jan 2, 2019 · 9 revisions

cpp-ipc - C++ IPC Library

基本使用方法

ipc::circ::queue

struct msg_t {
    int pid_;
    int dat_;
};

using queue_t = ipc::circ::queue<msg_t>;
auto msg_buff = new queue_t::array_t;

// thread 1

std::thread {
    [] {
        queue_t queue { msg_buff };
        for (int i = 0; i < 10; ++i) {
            queue.push(msg_t { 0, i });
        }
        queue.push(msg_t { -1, 0 });
    }
}.detach();

// thread 2

std::thread {
    [] {
        queue_t queue { msg_buff };
        queue.connect();
        while(1) {
            auto msg = queue->pop();
            if (msg.pid_ < 0) break;
            proc(msg);
        }
        queue.disconnect();
    }
}.detach();

Home
Tutorial

namespaces

classes

head files

Clone this wiki locally