Created
February 20, 2018 15:03
-
-
Save kuba-orlik/9f9b371acef96fede118e6fbc46537e9 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
main: startup | |
RESULT:1 | |
RESULT:2 | |
RESULT:191 | |
RESULT:285 | |
RESULT:403 | |
RESULT:520 | |
Segmentation fault (core dumped) |
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