On 9 August 2016 at 05:09, Nilesh Kokane <nilesh.kokan...@gmail.com> wrote: > On Aug 8, 2016 9:06 PM, "Thiago Macieira" <thiago.macie...@intel.com> wrote: >> >> On segunda-feira, 8 de agosto de 2016 20:11:38 PDT Nilesh Kokane wrote: >> > Hello, >> > >> > I've a QQueue designed for threadsafe as[1]. I push to the QQueue from >> > one thread and pop from the other. After several attempts it hangs in >> > QList::append near node_construct(n, t). >> > >> > [1]. https://paste.kde.org/p85706xzb
Your implementation looks a bit weird to me, what about simply (not tested): ThreadSafeQueue() { } ~ThreadSafeQueue() { } T pop() { QMutexLocker locker(&mutex); if (queue.isEmpty()) bufferNotEmpty.wait(&mutex); return queue.unqueue(); } push(T) { QMutexLocker locker(&mutex); queue.enqueue(t); bufferNotEmpty.wakeAll(); } isEmpty() // I doubt this will achieve what you're after, maybe you're after the notEmpty/notFull dual wait condition pattern [1] { QMutexLocker locker(&mutex); return queue.isEmpty(); } clear() { QMutexLocker locker(&mutex); queue.clear(); } And you could optimise a bit if you have several readers by using a QReadWriteLock instead of QMutex My 2 cents. Chris [1] eg. https://www.cs.mtu.edu/~shene/NSF-3/e-Book/MONITOR/ProducerConsumer-1/MON-example-buffer-1.html >> > >> > Any clue? >> >> node_construct can't hang. Your trace is wrong, that's not where it hung. > > http://picpaste.com/queue-Xsj4G4h8.png . This is what I get in stack trace. > > -- > Nilesh Kokane > > > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest > _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest