Could I disable the GTask Threadpool?

Can I disable the thread pool created by gtask? How should it be disabled if possible?

I noticed that when the same code is launched under X11, the application will not create so many threads, but if it is launched under wayland, it will create the same number of threads as the number of cores.

And I try to use gio::Task to manage tasks under rust, but I find it is not as convenient as using tokio, so I prefer to use tokio to manage my tasks.

So is this thread pool necessary? Even if it is, is it possible to reduce the number of threads some?

No, you can’t.

GLib does not care about the display server in use, so the cause is not X11 or Wayland.

1 Like

the previous image is from Hyprland, but when I running this app on x11(i3wm)

There are not those threads, I’m using the same code.

glib-networking 1:2.76.1-1
glib-perl 1.329.3-3
glib2 2.76.4-1
glib2-docs 2.76.4-1
glibc 2.37-3
glibmm 2.66.6-1
gtk-doc 1.33.2-3
gtk-layer-shell 0.8.1-1
gtk-update-icon-cache 1:4.10.4-1
gtk2 2.24.33-3
gtk3 1:3.24.38-1
gtk4 1:4.10.4-1
gtkmm 1:2.24.5-4
gtkmm3 3.24.7-1

there are the packages what I installed.

GLib does not care about the display server in use, so the cause is not X11 or Wayland.

I also think they should be the same, but I didn’t find out why it happened.

The thread pool will start any time GTK performs an async operation internally, AFAIK with the X11 backend that will happen whenever you perform a clipboard or drag and drop operation.

So no, there is no way to get any control of that outside of changing GTK internals. But I don’t understand why tokio is needed unless you have some other library that depends on it. You should not need to ever use gio::Task directly in regular app code. Use the MainContext::spawn functions for regular async futures, or use gio::spawn_blocking for a high-level way to access the gio thread pool.

1 Like

Thanks for your reply.

It looks like gio::spawn_blocking do not expose the cancellable argument to user, so is there a method missing here that exposes this parameter?

No, there is no need, you can just pass your cancellable through to the closure.

1 Like

Thanks, I’ll try it now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.