I am using GTK+3.0 in a embedded microprocessor. Our application mainly uses graph (Slope Graph) for displaying data from two sensors as a graph. We have implemented this as below.
1.A thread (running infinite while loop) is created from GTK app for acquiring real time data from sensors.
2.For updating the slope graph, I am using g_timeout_add function with 0 as time interval.
3.Inside the created thread, there will be a infinite while loop that will be getting data from sensors and it will plot the graph only when a start condition occurs and continue to plot till the stop condition occurs.
I am attaching the implementation here.
While doing so, The application gets crashed as the realloc of two array and plotting graph with those arrays seems to be happening at the same time.
I tried to add mutex lock and unlock for realloc part and also for the graph update part (inside g_timeout_add() ) but a dead lock is happening.
Is the above designed implementation correct? If not, Kindly help me with your ideas and suggestions.
Note: The array used here are global.
Also I am assuming that the app crash is because the g_timeout_add is not happening sequentially with the thread(it is behaving parallel like a new thread). The problem might be corrected if it works sequentially inside the thread.Is my assumption right?
Thanks for your time.