Closed hdhog closed 4 years ago
full example
CMakeLists.txt:
cmake_minimum_required(VERSION 3.14)
project(testQ)
file(GLOB SOURCES
"*.h"
"*.cpp"
)
add_executable(q_test ${SOURCES})
main.cpp:
#include <iostream>
#include <memory>
#include "MPMCQueue.h"
int main (int argc, char *argv[]) {
auto q = std::make_shared<rigtorp::MPMCQueue<int>>(10);
while(true) {
int v;
q->pop(v);
switch(v) {
case 4726:
std::cout << "event=" << v << " user removed\n";
break;
case 4724:
std::cout << "event=" << v << " user password manually reseted\n";
break;
default:
std::cout << "event=" << v << " unknow\n";
break;
}
}
return 0;
}
That's expected. This queue doesn't use futex for waiting. It's intended for high performance applications. If you want to be energy efficient you can use a std::mutex
+ std::condition_variable
with a std::deque
instead.
Used ~30% CPU on wait in pop. Compiled in VS2017
sample code: