Skip to content

A fast and lightweight message queue for inter-thread communication in C++11, with easy-to-use support for timeout events.

License

Notifications You must be signed in to change notification settings

gzz2000/MessageQueue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MessageQueue

A fast and lightweight message queue for inter-thread communication in C++11, with easy-to-use support for timeout events.

Example

See example.cpp. You can compile and run the example by the following commands.

cd <project directory>
make
./example

and the output will be

test
hello
end

How to use this

This is a header-only library. You can just copy messagequeue.hpp to your project and #include it in your source files.

To create a message queue:

messagequeue<Type> q;

To implement an event loop:

Type msg;
while(1) {
    msg = q.pop();     // will block until one is available
    process_message(msg);
}

To send a message to a queue: (which is probably used in another worker thread, and that thread will be unblocked)

q.push(msg);

To set a timeout message that will be automatically pushed into the queue after 500 milliseconds:

auto timer = q.setTimeout(msg, 500);

// probably cancel the timer before it alarms
q.clearTimeout(timer);

License

MIT License

About

A fast and lightweight message queue for inter-thread communication in C++11, with easy-to-use support for timeout events.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published