Data race in triangle example

I’m trying to recreate a data race in our production environment. So, I’m running the triangle-opengl example (GLFW version 3.4), with -fsanitize=thread and lo and behold:

$ ./examples/triangle-opengl
==================
WARNING: ThreadSanitizer: data race (pid=103603)
  Write of size 8 at 0x722c00005800 by main thread:
    #0 free ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:724 (libtsan.so.2+0x57c71) (BuildId: 38097064631f7912bd33117a9c83d08b42e15571)
    #1 <null> <null> (libgallium-25.0.7-0ubuntu0.24.04.2.so+0x554162) (BuildId: e4db5a0049ad7c33fdf8fbe94ff4971d4264e05c)
    #2 <null> <null> (libgallium-25.0.7-0ubuntu0.24.04.2.so+0xde6599) (BuildId: e4db5a0049ad7c33fdf8fbe94ff4971d4264e05c)
    #3 _glfwCreateWindowX11 /home/robin/Sandbox/glfw/src/x11_window.c:2007 (triangle-opengl+0x46a7d) (BuildId: 1a8e8bce19eba49572394b6a50f78094b37997f6)
    #4 glfwCreateWindow /home/robin/Sandbox/glfw/src/window.c:246 (triangle-opengl+0x27e37) (BuildId: 1a8e8bce19eba49572394b6a50f78094b37997f6)
    #5 main /home/robin/Sandbox/glfw/examples/triangle-opengl.c:94 (triangle-opengl+0x17962) (BuildId: 1a8e8bce19eba49572394b6a50f78094b37997f6)

  Previous write of size 8 at 0x722c00005800 by thread T1:
    #0 malloc ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:665 (libtsan.so.2+0x54b3f) (BuildId: 38097064631f7912bd33117a9c83d08b42e15571)
    #1 <null> <null> (libgallium-25.0.7-0ubuntu0.24.04.2.so+0x558f9c) (BuildId: e4db5a0049ad7c33fdf8fbe94ff4971d4264e05c)
    #2 <null> <null> (libgallium-25.0.7-0ubuntu0.24.04.2.so+0x56087f) (BuildId: e4db5a0049ad7c33fdf8fbe94ff4971d4264e05c)

  Thread T1 'triangl:disk$0' (tid=103605, running) created by main thread at:
    #0 pthread_create ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:1022 (libtsan.so.2+0x5ac1a) (BuildId: 38097064631f7912bd33117a9c83d08b42e15571)
    #1 <null> <null> (libgallium-25.0.7-0ubuntu0.24.04.2.so+0x5936f4) (BuildId: e4db5a0049ad7c33fdf8fbe94ff4971d4264e05c)
    #2 _glfwInitGLX /home/robin/Sandbox/glfw/src/glx_context.c:366 (triangle-opengl+0x4eda0) (BuildId: 1a8e8bce19eba49572394b6a50f78094b37997f6)
    #3 _glfwCreateWindowX11 /home/robin/Sandbox/glfw/src/x11_window.c:1975 (triangle-opengl+0x467fe) (BuildId: 1a8e8bce19eba49572394b6a50f78094b37997f6)
    #4 glfwCreateWindow /home/robin/Sandbox/glfw/src/window.c:246 (triangle-opengl+0x27e37) (BuildId: 1a8e8bce19eba49572394b6a50f78094b37997f6)
    #5 main /home/robin/Sandbox/glfw/examples/triangle-opengl.c:94 (triangle-opengl+0x17962) (BuildId: 1a8e8bce19eba49572394b6a50f78094b37997f6)

SUMMARY: ThreadSanitizer: data race (/lib/x86_64-linux-gnu/libgallium-25.0.7-0ubuntu0.24.04.2.so+0x554162) (BuildId: e4db5a0049ad7c33fdf8fbe94ff4971d4264e05c) 
==================
ThreadSanitizer: reported 1 warnings

Is this a ‘false positive’ in the sanitizer? Is this caused because of the way my system is set up (I’m on Ubuntu 24.04 btw)? Should I be worried?

Also, I read the documentation and realized this disk$0 thread has to do with on-disk cache. Consequently, I tried with export MESA_SHADER_CACHE_DISABLE=true , but this just results in even more data races.

This isn’t in GLFW itself, as it does no threading. The sanitizer output thinks this is in your libgallium library. I would suspect a false positive unless you are using a pre-release build of this library, but I can’t say for sure and I don’t know enough about libgallium to be of further help.