I am trying to display several curves with updates in real time of the displayed values. In order to do this, I launch my main window with GTK/Cairo/PLplot in the main program and a thread that generate the values to be displayed.
All of this being coded in Ocaml through dedicated bindings.

Each time that I need to change a curve from the thread, I reinitialize the plplot stream and create a new one with new values.
However, since I am using Cairo driver inside GTK, the generated graphs and window are also affected by GTK handler launched by signals that redraws the widget and thus the curves.

And unfortunately, some of these handler sometime launch at the same time as I am modifying some curves. This produces an error because some plplot stream are affected by commands in the wrong order (commands from the redraw in the handler and from the function to redraw curves with new values).
I tried to avoid this by the use of mutexes that forbids the use of some function from both the main window with GTK/Cairo/PLplot and from the thread.
However, this is not working.

My guess is that GTK and its Ocaml bindings, lablgtk, are handling threads and mutexes in a special way.
But my knowledge on this point is very sparse. And it would be very helpful if someone could help me on this point.

Thanks in advance for your time.

Johan Mazel