I think yeye_olive is trying to tell you that you can't push and pop atomically using a QList - in a multithreaded app, you need to protect access using a mutex if you want to ensure a writer doesn't corrupt what a reader is looking at.
I think yeye_olive is trying to tell you that you can't push and pop atomically using a QList - in a multithreaded app, you need to protect access using a mutex if you want to ensure a writer doesn't corrupt what a reader is looking at.
Indeed, general-purpose containers such as QList do not atomic push and pop operations. If you want to avoid synchronization with mutexes as much as possible, you need specialized containers; see, for instance, the Boot.Lockfree library.
However, the fact that the UI thread can inspect the whole container means that you will probably need heavy synchronization.
Thanks Yeye and d_stranz. Its good to know that its not trivial to atomically push and pop in any of the available qt containers.
Mutex isn't an option to me since it does add a lag to the UI thread.
For anyone interested in how I dealt with this:
I ended up creating a custom circular buffer with QAtomicInteger write pointer. I preallocate memory so my DataToDisc thread now just acts like a reader (without worrying about the growing list). Readers can never read beyond the write pointer and hence no corrupt data will ever be read. Works well!
Regards
Vikram
Bookmarks