Handle data structure between threads (gui thread and worker thread)
-
Hi,
I built an application that read data from UDP and present it on the GUI for the user.In the sequence picture ,
The architecture is UDP thread that read the data in high frequency, and emit the data to controller thread that process the data( to DB1).
When the controller finish to build the data block it emit(DB1) to the GUI Thread.
The GUI thread updating his data (DB2) according to DB1 and then refresh.The main thing bother me is that i have duplicate data structure DB
the controller hold some data structure (let say data for GUI to present) and the GUI hold other data structure DB that shown on the GUI.I built like this because i know that i not suppose to update data of the GUI thread in other thread.
my question
Is it ok to give ref of the GUI data structure to some worker thread that will update the data and in the end emit some update to the GUI thread to refresh ?
I open for other solutions or ideas to implement this. -
@Lior said in Handle data structure between threads (gui thread and worker thread):
Is it ok to give ref of the GUI data structure to some worker thread that will update the data and in the end emit some update to the GUI thread to refresh ?
As long as you make sure that there is no concurrent access - yes. See Synchronizing Threads as a starting point.
-
@Lior said in Handle data structure between threads (gui thread and worker thread):
Is it ok to give ref of the GUI data structure to some worker thread that will update the data and in the end emit some update to the GUI thread to refresh ?
As long as you make sure that there is no concurrent access - yes. See Synchronizing Threads as a starting point.
@Christian-Ehrlicher
Thanks for the quick response.what about the motto that i see everywhere in qt , "never access gui thread data outside of the main gui thread " ?
-
Hi,
The motto is: do not modify GUI elements outside the GUI thread.
Data are a different beast that obey the usual inter-thread rules.