Skip to content

Commit

Permalink
Safe closing of pthreads
Browse files Browse the repository at this point in the history
Fix order of subsystems clean-up.

NOTE: for some not-yet understood reason the exporting backthread doesn't keep
going after ctrl-q ???
  • Loading branch information
jenshannoschwalm committed Dec 20, 2024
1 parent b23418f commit 73ade98
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/common/darktable.c
Original file line number Diff line number Diff line change
@@ -2043,34 +2043,50 @@ void dt_cleanup()

dt_ctl_switch_mode_to("");
dt_dbus_destroy(darktable.dbus);

dt_lib_cleanup();
}
#ifdef USE_LUA
dt_lua_finalize();
#endif
dt_view_manager_cleanup(darktable.view_manager);
free(darktable.view_manager);
darktable.view_manager = NULL;
// we can no longer call dt_gui_process_events after this point, as that will cause a segfault
// if some delayed event fires

dt_image_cache_cleanup();
dt_mipmap_cache_cleanup();
/* How is darktable shutdown working?
dt_control_quit() is called via user request, it sets control->running anatomically
to shutdown mode and finally calls gtk_main_quit() so with current code we don't
have gtk events after that.
Quitting gtk means **we are exactly here** to continue the shutdown.
Anything requiring a still active UI must be done before ...
dt_control_shutdown() first waits for all threads to be joined, that means waiting for
all pipelined control jobs being processed.
So we have to ensure a full software stack including image_cache, mipmap_cache, darktable.imageio
and darktable.lib available until dt_control_shutdown() has finished.
After that we are sure there are no background threads running any more so we can
safely remove all mentioned subsystems.
*/
if(init_gui)
{
dt_control_shutdown();

dt_imageio_cleanup(darktable.imageio);
free(darktable.imageio);
darktable.imageio = NULL;
dt_control_shutdown();

dt_lib_cleanup();
dt_control_cleanup();
dt_undo_cleanup(darktable.undo);
darktable.undo = NULL;
free(darktable.gui);
darktable.gui = NULL;
}

dt_image_cache_cleanup();
dt_mipmap_cache_cleanup();

dt_colorspaces_cleanup(darktable.color_profiles);
dt_conf_cleanup(darktable.conf);
free(darktable.conf);

0 comments on commit 73ade98

Please sign in to comment.