Using std::thread to create GUI

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
nandakishore
Experienced Solver
Experienced Solver
Posts: 57
Joined: Wed Feb 25, 2015 2:09 pm
Location: Chennai, India

Using std::thread to create GUI

Post by nandakishore » Fri May 26, 2017 7:39 am

Hi ,
I have a situation that my panel contains some 50 controls which is well organized in column manner with sizer.
But to load the panel it is taking time like 2-3 seconds.
In order to avoid this i used std::thread for each column(6 std::threads for 6 columns) and i joined them.
But i'm facing a crash at t1.join() itself.
Any suggestions to avoid this?

PS:
I know that this will create a problem but still wanna give a try to a shot.
Got a Problem???..No worry..Focus on Solution not on Problem :P

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2057
Joined: Sun Jan 03, 2010 5:45 pm

Re: Using std::thread to create GUI

Post by PB » Fri May 26, 2017 7:52 am

nandakishore wrote:But i'm facing a crash at t1.join() itself.
Any suggestions to avoid this?
My suggestion: Make sure that you do not access any instance of GUI-related classes outside of the primary thread.

You could prepare the pure data in the secondary thread and send them to the main thread to be consumed by controls but from what you wrote that may not be the best idea. Users usually expect to see all the controls and have them filled upon opening a form and not having them pop-up or change their values after....

User avatar
doublemax
Moderator
Moderator
Posts: 14075
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Using std::thread to create GUI

Post by doublemax » Fri May 26, 2017 8:41 am

Don't touch the GUI from secondary threads. Ever.
I have a situation that my panel contains some 50 controls which is well organized in column manner with sizer.
But to load the panel it is taking time like 2-3 seconds.
Like i said in the other thread, creating 50 controls should not take that long. Please try to find out what exactly is slowing down the code. If you can't profile it, just comment everything out and put it back in piece by piece to narrow it down.
Use the source, Luke!

Post Reply