The worker constantly fills the (circular) buffer. What is not clear to me from the documentation is, how to work with a number of reading threads on this buffer without running into undefined parts of it or reading data twice.
For one consumer thread, my code was:
Converter::run()
{
int converted = 0;
while(!abort){
parentWindow->usedListSlots->acquire();
processEntry(threadBuffer[converted]);
parentWindow->freeListSlots->release();
converted++;
if (converted==300){
converted=0;
}
}
}
Converter::run()
{
int converted = 0;
while(!abort){
parentWindow->usedListSlots->acquire();
processEntry(threadBuffer[converted]);
parentWindow->freeListSlots->release();
converted++;
if (converted==300){
converted=0;
}
}
}
To copy to clipboard, switch view to plain text mode
The semaphore has a max value of 300, one for each item.
if I run 3 of these threads, I get random crashes, while the import/convert-loops are processed. So I thought, I'd have to work on different parts of the same buffer simultaneously.
But maybe I just got something completely wrong from the example.
Bookmarks