Hi, I was wondering whether I could have some views on the following.
My application uses a thread to run a simulation and generate simulation data. A thread is used so that my application’s GUI can remain responsive. Now, while a simulation is being run, my application’s main thread makes successive calls to QTimer::singleShot() to fetch any new simulation data that has been generated, as well as to plot whatever the user wants to visualise. The user can decide on what to visualise by creating/removing traces, this through my application’s GUI.
If I pre-select some traces and run a simulation, then everything works as expected. However, if, during a simulation, I remove a trace, then my application may crash. This is because the fetching function I call from QTimer::singleShot() goes through all the different traces and update them. Now, if a trace has been removed during a simulation and, more importantly, in the middle of my fetching function, then my fetching function might try to use a trace which doesn’t exist anymore, hence the crash.
So, what would you do to avoid this problem? I originally thought I could solve this problem by using a mutex, but that failed and I believe this might be because of my fetching function being called through QTimer::singleShot() and therefore running in its own thread?
Anyway, any idea/help on the above would be much appreciated…
Cheers, Alan.
↧