Hello all,

I know that Qt containers (QList in my case) are not thread-safe but they support reentrancy.

I have 3 threads:
  • DataGenerator thread
  • UI thread
  • DataToDisc thread


Their responsibility:
  • DataGenerator thread appends the generated data to a QList.
  • UI thread requests the latest data whenever it feels like!
  • DataToDisc thread reads from the beginning and writes the data to disc. It also removes this item from the list (to avoid large lists over time). This is done by using QList::takeFirst(). It does its job only if there are at least 'n' elements in the list. So I am not accessing the same element from multiple threads.


So my question is: Is this approach wrong? I get occasional crashes with the takeFirst(). Could that be because this function causes a list "reordering" or something thereby causing undefined behavior.

Should I not use QList for this purpose?

Thanks

Regards
Vikram