PDA

View Full Version : Worker thread tasks slowdown due to windows minimise and maximise events



jessiemmichael
8th September 2009, 04:27
I have worker thread to receive image data tcp socket and queue up that data.

Worker thread has more priority that it should not delay receiving data.

When the UI application is minimised or maximised, it influence the worker thread. A delay is observed in the worker thread.

I read some article that windows minimise and maximise events are sent using SendMessage. why it disturbs the worker thread tasks.

wysota
8th September 2009, 08:41
Please provide a minimal compilable example reproducing the problem.

jessiemmichael
8th September 2009, 09:17
// thread to receive data
CConnectionThread::CConnectionThread(QObject *parent)
: QThread(parent)
{

}

void CConnectionThread::initConnections()
{

m_DataHandler = new CDataHandler(0);
m_DataHandler->initConnections();

}

void CConnectionThread::run()
{
initConnections();
exec();

}


void CDataHandler::initConnections()
{
m_Connection= new QTcpSocket();

m_Connection->connectToHost(ipAddress, portNumber);
m_Connection->waitForConnected(2000);

bool ret = connect(m_Connection, SIGNAL(readyRead()), this, SLOT(dataAvailable()));


}

/// data handler class to parse the data from the port and queue up for processing
void CDataHandler::dataAvailable()
{

QByteArray* response;
/// read the length of response
/// read the complete response

processResponse(response);
delete(response);

}

void CDataHandler::processResponse(QByteArray* buffer)
{
// get response id
switch(responseId)
{
case IMAGE_DATA:
addToImageQueue(buffer); /// queue of QByteArray* that can be accessible to Both UI and worker thread
break;
case NUMERIC_DATA:
addToNumericQueue(buffer);
emit newDataArrived();
break;
}

}

The worker thread is to read the data from the tcp socket, it should not get affected by any of the UI events. Ideally tcp server should not get slow down.
Tcp server sends image data for every 1 ms.

wysota
8th September 2009, 09:23
This is not a compilable example.

Even though I can see that the code is probably (I can't know for sure without seeing the bigger image) wrong - your thread does completely nothing, all the data reading takes place in the main thread.

jessiemmichael
11th September 2009, 05:23
I tried to simulate the issue with sample application. It is a console application. The application simply reads the data from the desired port. (I am not able to send the code for Tcp server, since it is camera device that keep sending image data).

When I simulate the issue, I fould out that the issue is due to windows manager that takes more time duing minimize and maximize events and caues a delay of 500 ms.

If the application has to run in real time environment, it should reside in kernal. Or probably need to directly interact with TCP stack.

Thanks to wysota.