Skip to content

Instantly share code, notes, and snippets.

@kuba-orlik
Created February 20, 2018 15:01
Show Gist options
  • Save kuba-orlik/1fee8a9a0fadd3b29f0a4baba3811ff7 to your computer and use it in GitHub Desktop.
Save kuba-orlik/1fee8a9a0fadd3b29f0a4baba3811ff7 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <boost/thread.hpp>
#include <boost/functional.hpp>
#include <boost/lockfree/spsc_queue.hpp>
using namespace std;
void workerFunc(const char* msg, boost::lockfree::spsc_queue<int, boost::lockfree::capacity<1024>> *queue)
{
for(int i=1; i<=1000; i++){
queue->push(i);
}
cout << "DONE";
}
int main()
{
std::cout << "main: startup" << std::endl;
boost::lockfree::spsc_queue<int, boost::lockfree::capacity<1024>> queue;
const char* name = "Hello world";
boost::thread workerThread(workerFunc, name, &queue);
int result = 0;
bool has;
while(true){
has = queue.pop(&result);
if(has){
cout << " RESULT:" << result << " " << has << endl;
}else {
cout << has;
}
}
// edit: fixed in response to comment
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment