CodePudding user response:
Emphasize: GTK is not thread-safe, such as fruit to create a thread, and then refresh the interface in the thread, could not get the desired results and may even cause crashes,Step 1:
//initializes the thread safety
if ( ! G_thread_supported ())
{
Printf (" [% s] - Init g_thread. J/r/n ", __FUNCTION__);
G_thread_init (NULL);
Gdk_threads_init ();
}
Step 2:
Gdk_threads_enter ();
Gtk_main ();
Gdk_threads_leave;
Step 3:
Gdk_threads_enter ();
.//refresh the UI
Gdk_threads_leave;