In my application I have the need to use 4 threads. There is the GUI thread (which only handles GUI related stuff), the second thread (Sensor Thread) is responsible for receiving and filtering some sensor data from a network socket, the third (Control Thread) and forth thread (AI thread) handles some heavy work. To communicate between them I'm using signals and slots.
After the second thread has finished filtering the last received data it emits a signal with the data to the other 3 threads.
My problem is that it takes more than 5ms (timing is very crucial for this application) for the Sensor thread to emit the signal. But that does not happen when the AI and Control threads aren't connected.
I am already using QueuedConnection (default) and passing the data as a const pointer. The data is an object of a class I'm using and the size of it is about 1.2Kb (got it using sizeof(ClassData) )
The slots doesn't do heavy computation, it just updates the data in the current thread.
The code that emits the data looks like this:
void filterData()
{
filteredData = filter(networkData); // Filters the network data
// Emits a signal with the filtered data
QElapsedTimer measureTime; measureTime.start();
emit sendFilteredData(filteredData);
qDebug() << measureTime.nsecsElapsed()/1e6; // Shows measured time in ms
}