Skip to content

Instantly share code, notes, and snippets.

@Craigson
Last active July 24, 2017 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Craigson/cc217da3638daa2724bfec6efbc1d6f1 to your computer and use it in GitHub Desktop.
Save Craigson/cc217da3638daa2724bfec6efbc1d6f1 to your computer and use it in GitHub Desktop.
concurrent_buffer.cpp
ConcurrentCircularBuffer<Surface8u> *mFrameQueue;
std::thread mWorkerThread;
setup(){
mFrameQueue = new ConcurrentCircularBuffer<Surface8u>(90);
mWorkerThread = std::thread([&] {
console() << "CREATING WORKER THREAD " << std::endl;
static int kNextFrame = 0;
static bool running = true;
while (running)
{
while (mFrameQueue->isNotEmpty()) {
Surface8u frame;
mFrameQueue->popBack(&frame);
writeImage("Frame_" + std::to_string(kNextFrame++) + ".png", frame);
//mMovieWriters[mMovieWriters.size() - 1]->addFrame(frame, 1.f / 30.f);
};
};
});
}
update()
{
mFrameQueue->pushFront(*mCameraManager.getSurface()); // checks internally if a new frame is available
console() << "update: size of mFrameQueue: " << mFrameQueue->getSize() << std::endl;
}
/*
Errors:
Microsoft C++ exception: std::bad_alloc at memory location 0x0019F8BC.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment