Skip to content

Segfault on thread destruction with Wayland but not X11. #2536

Open
@pascal-boeschoten-hapteon

Description

When running this program, I get a segfault when running under Wayland, but X11 is fine.
The segfault occurs when the std::jthread is being destroyed.

#include <cassert>
#include <thread>
#include <GLFW/glfw3.h>

int main() {
  std::jthread gui_thread{[] {
    assert(glfwInit() == GLFW_TRUE);
    auto window = glfwCreateWindow(1280, 720, "title", nullptr, nullptr);
    assert(window);
    glfwDestroyWindow(window); // NOTE: Not necessary to reproduce.
    glfwTerminate();
    assert(glfwGetError(nullptr) == 0);
  }};
  assert(glfwGetError(nullptr) == 0);
  return 0;
}

OS and version: Ubuntu 22.04.4 LTS
Release or commit: 228e58262e18f2ee61799bd86d0be718b1e31f9f

Error messages:

Segmentation fault (core dumped)

Call stack:

Thread 1
#0  __futex_abstimed_wait_common64 (private=128, cancel=true, abstime=0x0, op=265, expected=74121, futex_word=0x7ffff4dc6910) at ./nptl/futex-internal.c:57
#1  __futex_abstimed_wait_common (cancel=true, private=128, abstime=0x0, clockid=0, expected=74121, futex_word=0x7ffff4dc6910) at ./nptl/futex-internal.c:87
#2  __GI___futex_abstimed_wait_cancelable64 (futex_word=futex_word@entry=0x7ffff4dc6910, expected=74121, clockid=clockid@entry=0, abstime=abstime@entry=0x0, private=private@entry=128)
    at ./nptl/futex-internal.c:139
#3  0x00007ffff5a96624 in __pthread_clockjoin_ex (threadid=140737301472832, thread_return=0x0, clockid=0, abstime=0x0, block=<optimised out>) at ./nptl/pthread_join_common.c:105
#4  0x00007ffff56e8567 in __gthread_join (__value_ptr=0x0, __threadid=<optimised out>)
    at [...]/libstdc++-v3/include/x86_64-pc-linux-gnu/bits/gthr-default.h:669
#5  std::thread::join (this=0x7fffffffdd90) at [...]/libstdc++-v3/src/c++11/thread.cc:134
#6  0x00005555555578b9 in std::jthread::join (this=0x7fffffffdd88) at [...]/gcc/x86_64-pc-linux-gnu/13.2.0/../../../../include/c++/13.2.0/thread:191
#7  0x0000555555557818 in std::jthread::~jthread (this=0x7fffffffdd88) at [...]/gcc/x86_64-pc-linux-gnu/13.2.0/../../../../include/c++/13.2.0/thread:161
#8  0x0000555555557317 in main () at [...]/main.cpp:22

Thread 2
#0  0x00007ffff4392d30 in ?? ()
#1  0x00007ffff5a91691 in __GI___nptl_deallocate_tsd () at ./nptl/nptl_deallocate_tsd.c:73
#2  __GI___nptl_deallocate_tsd () at ./nptl/nptl_deallocate_tsd.c:22
#3  0x00007ffff5a9494a in start_thread (arg=<optimised out>) at ./nptl/pthread_create.c:453
#4  0x00007ffff5b26850 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions