Using Gio::DBus::own_name in mutiple thread will crash
When I own different name in different thread, it will crash sometimes.
And there is no c++ interface of g_main_context_push_thread_default
and g_main_context_pop_thread_default
glibmm:2.58.1
future_ = std::async(std::launch::async, [this]() {
auto context = Glib::MainContext::create();
g_main_context_push_thread_default(context->gobj());
auto ml = Glib::MainLoop::create(context, false);
auto OnBusAcquired =
[&](const Glib::RefPtr<Gio::DBus::Connection>& connection,
const Glib::ustring& name) {
// register_object...
};
auto OnNameAcquired =
[&](const Glib::RefPtr<Gio::DBus::Connection>& /* connection */,
const Glib::ustring& name) {
// ...
};
auto OnNameLost =
[&](const Glib::RefPtr<Gio::DBus::Connection>& /* connection */,
const Glib::ustring& name) {
// ...
};
auto connection_id = Gio::DBus::own_name(
Gio::DBus::BUS_TYPE_SYSTEM, bus_name_, OnBusAcquired,
OnNameAcquired, OnNameLost);
ml->run();
Gio::DBus::unown_name(connection_id);
g_main_context_pop_thread_default(context.get()->gobj());
});