I got hit by the same bug these last days and I've built a minimal reproducible case based on the problem I met. The main trouble comes from the constructor attribute which is used while the call order of constructor is undefined. This can be fixed by setting the priority of the constructor in mingw-w64-libraries/winpthreads/src/misc.c to 0.