Created
February 20, 2018 15:01
-
-
Save kuba-orlik/1fee8a9a0fadd3b29f0a4baba3811ff7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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