swankster
28th August 2017, 15:07
I have a application that parses a UDP stream. Then monitor that stream for a trigger event to start my thread. within that thread is a worker thread that calls a function which contains a static QVector. On every trigger event I initiate a vector.swap and vector.resize/reserve (have used both with same results).
with the program running and continually receiving UDP data. It runs beautifully with not issues. This data is then written to MySQL. a second thread is also running and writing reference data to another table in MySQL. Both MySQL write functions are on separate connections.
However if my program is left running overnight with no UPD stream. My program will hang and must be re-started to work again. This is not the case with 4 hours of no UDP. I have not determined a specific time as of yet. Not sure if my issue id with my Thread or my Vector. The 2nd thread function will pick up and continue to run normally.
Below are a few code snippets.
System Windows 7 Prof.
creator 4.1.0
Qt 5.6.2(Gcc 6.1.0, 64 bit)
using C++11
[Main Thread]
{
frmThread = new QThread;
workerThread = new StreamToVector();
workerThread->moveToThread(frmThread);
connect(workerThread, &DataStreamToVector::destroyed, frmThread, &QThread::quit);
connect(workerThread, &DataStreamToVector::destroyed, workerThread, &DataStreamToVector::deleteLater);
connect(this, &DataStreamToBuffer::DataToVector_Signal, workerThread, &DataStreamToVector::parseStreamToVector_Slot, Qt::DirectConnection);
frmThread->start();
DataToVector_Signal(dataStream, dataSize, RecordsPerTriggerEvent);
}
[worker thread .h ]
QThread *frmThread;
[worker thread .cpp ]
void DataStreamToVector::parseStreamToVector_Slot(QStri ng dataStream, int dataSize, uint RecordsPerTriggerEvent)
{
static QVector < QVector<QString> > cycleBuffer(63, QVector<QString>(MAX_CYCLE_SIZE_x10MS));
static uint recordCnt = 1;
if ( recordCnt > RecordsPerTriggerEvent ) {
QVector < QVector<QString> > defaultBuffer(63, QVector<QString>(MAX_CYCLE_SIZE_x10MS));
recordCnt = 1;
cycleBuffer.swap(defaultBuffer);
cycleBuffer.reserve(GALIL_40x0_ADDRESS_COUNT);
}
if ( recordCnt <= recPerCycle ) {
cycleBuffer[0][recordCnt].append(dataStream.mid( 12,2 )); // general Input Block 0 address
cycleBuffer[1][recordCnt].append(dataStream.mid( 14,2 ));
// recordCnt typically 350 - 800
if ( recordCnt == RecordsPerTriggerEvent )
writeRecordsToDB(RecordsPerTriggerEvent, cycleBuffer);
recordCnt++;
}
any insight or direction would be appreciated. Thank You,
with the program running and continually receiving UDP data. It runs beautifully with not issues. This data is then written to MySQL. a second thread is also running and writing reference data to another table in MySQL. Both MySQL write functions are on separate connections.
However if my program is left running overnight with no UPD stream. My program will hang and must be re-started to work again. This is not the case with 4 hours of no UDP. I have not determined a specific time as of yet. Not sure if my issue id with my Thread or my Vector. The 2nd thread function will pick up and continue to run normally.
Below are a few code snippets.
System Windows 7 Prof.
creator 4.1.0
Qt 5.6.2(Gcc 6.1.0, 64 bit)
using C++11
[Main Thread]
{
frmThread = new QThread;
workerThread = new StreamToVector();
workerThread->moveToThread(frmThread);
connect(workerThread, &DataStreamToVector::destroyed, frmThread, &QThread::quit);
connect(workerThread, &DataStreamToVector::destroyed, workerThread, &DataStreamToVector::deleteLater);
connect(this, &DataStreamToBuffer::DataToVector_Signal, workerThread, &DataStreamToVector::parseStreamToVector_Slot, Qt::DirectConnection);
frmThread->start();
DataToVector_Signal(dataStream, dataSize, RecordsPerTriggerEvent);
}
[worker thread .h ]
QThread *frmThread;
[worker thread .cpp ]
void DataStreamToVector::parseStreamToVector_Slot(QStri ng dataStream, int dataSize, uint RecordsPerTriggerEvent)
{
static QVector < QVector<QString> > cycleBuffer(63, QVector<QString>(MAX_CYCLE_SIZE_x10MS));
static uint recordCnt = 1;
if ( recordCnt > RecordsPerTriggerEvent ) {
QVector < QVector<QString> > defaultBuffer(63, QVector<QString>(MAX_CYCLE_SIZE_x10MS));
recordCnt = 1;
cycleBuffer.swap(defaultBuffer);
cycleBuffer.reserve(GALIL_40x0_ADDRESS_COUNT);
}
if ( recordCnt <= recPerCycle ) {
cycleBuffer[0][recordCnt].append(dataStream.mid( 12,2 )); // general Input Block 0 address
cycleBuffer[1][recordCnt].append(dataStream.mid( 14,2 ));
// recordCnt typically 350 - 800
if ( recordCnt == RecordsPerTriggerEvent )
writeRecordsToDB(RecordsPerTriggerEvent, cycleBuffer);
recordCnt++;
}
any insight or direction would be appreciated. Thank You,