I have a compiled ROOT C++ program and created a canvas that needs some refresh.
I usually use gSystem->ProcessEvent(). However there is a time consuming calculation part.
I was thinking to make my computation on any other thread and keep the graphics on the main side
Would you have any suggestion to do so with ROOT ? Should I just use std::thread maybe ?
In particular how to detect when histogram are ready ? It seems the drawing can only be done in the main thread
I have been able to do what I needed with std::thread… but sometimes I get my program to crash.
I made sure that my workers finished before refreshing and going to the next iteration.
It looks like my canvas don’t like to be modified while redrawing it. Any suggestion ?
Assertion failed: ((!E || isa<DeclRefExpr>(E) || isa<MemberExpr>(E) || isa<FunctionParmPackExpr>(E)) && "Invalid Expr argument to DoMarkVarDeclReferenced"), function DoMarkVarDeclReferenced, file SemaExpr.cpp, line 18538.
Abort trap: 6
Yes, if you are using normal ROOT graphics, it is only possible to update graphics from the main thread - where ROOT application runs and event processing is performed. You also should be aware that histograms or graphs, shown in the canvases, should not be modified from other threads - otherwise you can get concurrency conflicts.
In your case you can run computation with histograms/graphs filling in separate thread and use any signaling mechanism - condition_variable, semaphore, simple atomic variable - to transfer these graphical objects to main thread, there they will be displayed.
Since recently ROOT provides web-based implementation for TCanvas. It always can be tested
by running root --web=chrome or specifying gROOT->SetWebDisplay("chrome");.
It makes much less troubles when used in multi-threaded environment while graphics rendering performed in web browser and not in the applications threads. And it much less depends from gPad.
As alternative, you can try RCanvas and check tutorials/rcanvas/rcanvas_mt.cxx example.
This new canvas was designed to work properly in multithreaded environment.
It fully supports all histograms and graphs classes, which can be displayed with web-based TCanvas.
Note that whenever you want to modify something from the GUI, you should use add the following in the member functions accessed by external threads
What do you mean by “modify something” ?
Deleting an histogram should be done before calling R__LOCKGUARD(&fGuiMutex); ?
I have actually a set of histograms that is being deleted on the fly (to free some memory), and some other being created… if I understand well, I should call something like: