I do not know what the heck is wrong with my code that it never Dequeus the queue, instead isEmpty always meets true.
here's the queue class:
Code:
class ConcurrentQueue { private: QQueue<QByteArray> dataStore; public: bool isEmpty(); private: QMutex mutex; }; { qDebug() << dataStore.length(); mutex.lock(); dataStore.enqueue(value); mutex.unlock(); qDebug() << dataStore.length(); } { // mutex.lock(); // return dataStore.dequeue(); // mutex.unlock(); QByteArray tmp; mutex.lock(); if(!dataStore.isEmpty()) { tmp = dataStore.dequeue(); } mutex.unlock(); return tmp; } bool ConcurrentQueue::isEmpty() { return dataStore.isEmpty(); }
next a timer is connected to a slot to Enqueu a packet every lt's say 10 milliseconds:
Code:
//qDebug() << built.toHex(); qDebug() << "EnQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ"; queue.Enqueue(built);
A thread regularly checks if this queue is not empty it dequeues the queue and does something, but isEmplty always returns true!
Code:
if(queue.isEmpty()) { qDebug() << "#####################################"; return; } //NEVER COMES HERE!
here's the thread:
Code:
Write::Write() { } void Write::run(){ while(1) { rs.writeToSerialPort(); // in this function above always isemplty is true this->msleep(10); } }
Added after 31 minutes:
as I run the code, queue size increases and the contents are enQd inside of it. but I wonder why isEmpty always meets !!!!