5

I am using Ubuntu 20.04 LTS. The kernel version is 5.4.0-42.

Here is an example program:

// mre.c // Compile with: cc -o mre mre.c -lSDL2 #include <stdio.h> #include <SDL2/SDL.h> int main(void) { SDL_Init(SDL_INIT_VIDEO); // Doesn't work without SDL_INIT_VIDEO getchar(); } 

When I look at the running program ./mre in htop with thread names turned on, I see it has these four threads:

  • mre:disk$3
  • mre:disk$2
  • mre:disk$1
  • mre:disk$0

And here are some threads of /usr/libexec/ibus-x11 with similar names:

  • ibus-x1:disk$3
  • ibus-x1:disk$2
  • ibus-x1:disk$1
  • ibus-x1:disk$0

Many programs don't have them (maybe they aren't using a certain graphical interface?)

Such threads always come in fours (my computer has four cores) and are listed in descending order. /usr/lib/xorg/Xorg has eight of these threads, two of each number 0-3. What are they for?

4
  • 1
    Please relace screenshots with plain text encapsulated in ``` text ``` Commented Aug 23, 2020 at 13:41
  • Can you point to the source code of your C++ program, or else provide some minimal reproducible example? Commented Aug 23, 2020 at 20:16
  • Is github.com/TurkeyMcMac/anosmellya your program? If yes, mention it in your question Commented Aug 23, 2020 at 20:17
  • I'm guessing the threads have something to due with using X11, but I'm not sure. Commented Aug 23, 2020 at 23:34

2 Answers 2

5

Those threads are used for the mesa disk cache:

 util_queue_init(&cache->cache_queue, "disk$", 32, 4, UTIL_QUEUE_INIT_RESIZE_IF_FULL | UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY | UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY); 

https://sources.debian.org/src/mesa/22.0.3-1/src/util/disk_cache.c/?hl=174#L174

And inside util_queue_init() then:

 /* Form the thread name from process_name and name, limited to 13 * characters. Characters 14-15 are reserved for the thread number. * Character 16 should be 0. Final form: "process:name12" * * If name is too long, it's truncated. If any space is left, the process * name fills it. */ 

https://sources.debian.org/src/mesa/22.0.3-1/src/util/u_queue.c/?hl=405#L414-L420

Thus, all GUI processes that somehow call into that mesa code create those extra threads, e.g. on a f33 desktop system of mine:

 pid tid comm cls 1942 1989 gnome-s:disk$0 BAT 1942 1990 gnome-s:disk$1 BAT 1942 1991 gnome-s:disk$2 BAT 1942 1992 gnome-s:disk$3 BAT 2041 2237 Xwaylan:disk$0 BAT 2041 2238 Xwaylan:disk$1 BAT 2041 2239 Xwaylan:disk$2 BAT 2041 2240 Xwaylan:disk$3 BAT 2041 2259 Xwaylan:disk$0 BAT 2041 2260 Xwaylan:disk$1 BAT 2041 2261 Xwaylan:disk$2 BAT 2041 2262 Xwaylan:disk$3 BAT 2292 2325 gsd-xse:disk$0 BAT 2292 2326 gsd-xse:disk$1 BAT 2292 2327 gsd-xse:disk$2 BAT 2292 2328 gsd-xse:disk$3 BAT 2307 2344 ibus-x1:disk$0 BAT 2307 2345 ibus-x1:disk$1 BAT 2307 2346 ibus-x1:disk$2 BAT 2307 2347 ibus-x1:disk$3 BAT 2464 2578 firefox:disk$0 BAT 2464 2579 firefox:disk$1 BAT 2464 2580 firefox:disk$2 BAT 2464 2581 firefox:disk$3 BAT 2756 2785 firefox:disk$0 BAT 2756 2786 firefox:disk$1 BAT 2756 2787 firefox:disk$2 BAT 2756 2788 firefox:disk$3 BAT 2806 2841 firefox:disk$0 BAT 2806 2842 firefox:disk$1 BAT 2806 2843 firefox:disk$2 BAT 2806 2844 firefox:disk$3 BAT 2919 3078 firefox:disk$0 BAT 2919 3079 firefox:disk$1 BAT 2919 3080 firefox:disk$2 BAT 2919 3081 firefox:disk$3 BAT 3346 3367 firefox:disk$0 BAT 3346 3368 firefox:disk$1 BAT 3346 3369 firefox:disk$2 BAT 3346 3370 firefox:disk$3 BAT 3408 3426 firefox:disk$0 BAT 3408 3427 firefox:disk$1 BAT 3408 3428 firefox:disk$2 BAT 3408 3429 firefox:disk$3 BAT 5794 5825 firefox:disk$0 BAT 5794 5826 firefox:disk$1 BAT 5794 5827 firefox:disk$2 BAT 5794 5828 firefox:disk$3 BAT 6345 6364 firefox:disk$0 BAT 6345 6365 firefox:disk$1 BAT 6345 6366 firefox:disk$2 BAT 6345 6367 firefox:disk$3 BAT 9502 9525 firefox:disk$0 BAT 9502 9526 firefox:disk$1 BAT 9502 9527 firefox:disk$2 BAT 9502 9528 firefox:disk$3 BAT 22548 22565 firefox:disk$0 BAT 22548 22566 firefox:disk$1 BAT 22548 22567 firefox:disk$2 BAT 22548 22568 firefox:disk$3 BAT 33788 33807 vlc:disk$0 BAT 33788 33808 vlc:disk$1 BAT 33788 33809 vlc:disk$2 BAT 33788 33810 vlc:disk$3 BAT 48178 74574 kwallet:disk$0 BAT 48178 74575 kwallet:disk$1 BAT 48178 74576 kwallet:disk$2 BAT 48178 74577 kwallet:disk$3 BAT 60824 60830 chromiu:disk$0 BAT 60824 60831 chromiu:disk$1 BAT 60824 60832 chromiu:disk$2 BAT 60824 60833 chromiu:disk$3 BAT 69502 69519 firefox:disk$0 BAT 69502 69520 firefox:disk$1 BAT 69502 69521 firefox:disk$2 BAT 69502 69522 firefox:disk$3 BAT 
2
  • 1
    Great info! Do the threads named sh0, sh1, sh2 etc, also stem from Mesa? And what about gdrv0 thread? Commented May 20, 2022 at 18:19
  • 1
    @Bram yes, the sh threads and gdrv threads are also created by mesa. Commented May 20, 2022 at 19:03
0

On Linux, a C or C++ program can use pthread_setname_np(3) -using prctl(2) system call- to change the thread name.

If the developer of your binary (or of a library used by your program, such as libSDL) decided to call that function, it usually succeeds.

You might use gdb(1), strace(1), ltrace(1) to investigate more. Or study the source code of libSDL

If you use the GCC compiler, compile your C++ code with g++ -Wall -Wextra -g (and perhaps recompile libSDL from its source code, and at least study its source code since it is open source).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.