[Qt-interest] Locking across GUI / Simulation and Signal Slots

Matthias Pospiech matthias.pospiech at gmx.de
Tue Jan 20 21:24:57 CET 2009


I have a signal in the simulation class which triggers plotting 
functions (GUI), which then access the Simulation data.
However if the plotting coincidences which a reset of the data (which 
happes at the end of a simulation run, which always also triggers a plot 
update),
then it is very likely that while the plotting function is retreiving 
the data, the same array are deleted -> crash.

Now I do not know how to implement locking. What I do now is this

void MainWindow::updatePlotsTimeSpectrum()
{
    Laser->data->setDeleteLocked(true);
    fillPlot(1, Laser->data->TimeAxis(), Laser->data->TimeAmplitude(), 
Laser->data->Size());
    fillPlot(2, Laser->data->SpectralAxis(), 
Laser->data->SpectralAmplitude(), Laser->data->Size());
    fillPlot(3, Laser->data->TimeAxis(), Laser->data->TimePhase(), 
Laser->data->Size());
    fillPlot(4, Laser->data->SpectralAxis(), 
Laser->data->SpectralPhase(), Laser->data->Size());   
    Laser->data->setDeleteLocked(false);
}

void LaserData::deleteArrays()
{
    while (isDeleteLocked)
        { delay(200);} //!< Wait until Arrays are unlocked
   
    delete [] TA;
    delete [] SA;
    delete [] AA;
...
}

The best solution would be if I could check directly after the emit 
which triggers updatePlotsTimeSpectrum(), that this has finished.
Any usual solution to such a problem?



More information about the Qt-interest-old mailing list