ofThreadChannel clear queue


I had a look at ofThreadChannel and seems to be a very clean and easy way to do threaded image processing.

Problem is that some process might take quite some time. So i tried the example and added a crazy sleeping time in the middle of the threaded process function. Of course, turns out that the queue holding frames keeps increasing, creating a dangerous memory leak. I was wondering if these lines should go to ofThreadChannel class, put them here if anyone needs them.

/// \brief Return the size of the queue.
int size(){
	std::unique_lock<std::mutex> lock(mutex);
	return queue.size();

/// \brief Remove all the elements of the queue.
void clear(){
	std::unique_lock<std::mutex> lock(mutex);
	queue = {};

There is an example showing the issue here:


what we need is a second thread channel class or an option when it’s created where the channel is bound with a certain capacity so trying to add more elemnts than that will fail

also what i usually do in this cases (and also makes processing faster) is using a pool of pixels and send the pixels (or a pointer) along with the task and then when the thread is done return the pixels to the main thread through another channel. That effectively limits the tasks that there can be and also avoids extra allocations

this addon for example: https://github.com/arturoc/ofxTextureRecorder does that


Thank you very much! i will have a look!