Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling chess engine stockfish with MSYS2 using mingw-w64-x86_64-libwinpthread-git-7.0.0.5447 (and later versions) #5610

Closed
CoffeeOne opened this issue Jul 13, 2019 · 23 comments

Comments

@CoffeeOne
Copy link

After compiling the open source engine stockfish, I have problems to run the builtin benchmark of it ("bench"). So compiling is still fine, but I have hangs. It seems to be related with threading, but unfortunately I am not able to debug this issue.
official-stockfish/Stockfish#222
My SYS2 is fully updated, to compile stockfish I basically need only make and mingw-w64-x86_64-gcc. It has defintely something to do with the build tool-chain, because replacing the mingw64 folder with a mingw from Sourceforge (latest is only gcc 8.1.0 there) made the problem go away.

I manually downgraded libwinpthread-1.dll by downloading
http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-libwinpthread-git-7.0.0.5447.a2d94c81-1-any.pkg.tar.xz
and putting (overwriting the existing) to C:\msys64\mingw64\bin

I am still testing, but the problem seems to be gone now.
Can you check if something is wrong with the latest libwinpthread?

@mati865
Copy link
Collaborator

mati865 commented Jul 14, 2019

There were locking changes in winpthreads recently.
cc @lhmouse

@lhmouse
Copy link
Contributor

lhmouse commented Jul 14, 2019

See the commit here.

There have been reports about deadlocks here and here, which don't deadlock on Linux. With the most recent two commits these deadlocks are eliminated.

Perhaps you may have a look at this patch. You may re-build winpthreads with this patch applied and see whether it still causes deadlocks. (This patch might no longer apply to master. Please edit by hand.)

@oscarfv
Copy link
Contributor

oscarfv commented Jul 14, 2019

@mati865 : where? Looking at https://sourceforge.net/p/mingw-w64/mingw-w64/ci/a6f0bf18209b9a2d4e51dd121df03d9dcfbc9838/log/?path=/mingw-w64-libraries/winpthreads the last changes were made 2019-04-26 and the version that the OP reports as working (7.0.0.5447.a2d94c81-1) contained those changes.

@CoffeeOne
Copy link
Author

Hello,
I am sorry, but with the copying of dlls, I messed up my msys2 installation, so I started over.
I moved away the existing msys64 folder, downloaded msys2-x86_64-20190524.exe, installed it, executed the msys2_shell.cmd, updated all packages.
Then I installed pacman -S git make vim mingw-w64-x86_64-gcc

=> The issue (my created binary produces hangs) is still here, it's 100% reproducible. By using an alternative mingw (additional mingw-810 folder and setting temporarily PATH="/mingw64-810/bin:${PATH}"), I am able to produce a good binary.
It's very unlikely a problem in the stockfish source code, because the problem also occurs when I compile the sources from stockfish 10 (Nov 2018).

I always keep my msys2 up to date, so I don't know exactly when it broke, I did not have the problem with older msys2 gcc versions.

So my question is: What is the best way, to downgrade for example to mingw-w64-x86_64-gcc 9.1.0-2???

@oscarfv
Copy link
Contributor

oscarfv commented Jul 14, 2019

@CoffeeOne : download the gcc package from repo.msys2.org (you will need the gcc-libs package for the same version too) and then

pacman -U package-file package-file...

You need to list the gcc and the gcc-libs packages on the same command above, because their versions must match and pacman will complain if you try to install them separately.

@CoffeeOne
Copy link
Author

CoffeeOne commented Jul 14, 2019

@oscarfv Thx!
I started down and upgrading packages like a mad monkey :D
I found the (for me!) offending packages.
I am on all latest (so gcc 9.1.0-3), but I downgraded:

pacman -U mingw-w64-x86_64-libwinpthread-git-7.0.0.5325.11a5459d-1-any.pkg.tar.xz mingw-w64-x86_64-winpthreads-git-7.0.0.5325.11a5459d-1-any.pkg.tar.xz

That works now 100% for me, no more hangs in my self compiled stockfish.exe

@lhmouse
Copy link
Contributor

lhmouse commented Jul 14, 2019

5325 denotes the roughly 155th commit preceding HEAD, so I presume it is around 52f2ce12 (with the subject ' Ensure wait timeouts are respected') that the offending commit is located.

@CoffeeOne
Copy link
Author

CoffeeOne commented Jul 14, 2019

Sorry for for just wild guessing, but isn't this main change
https://sourceforge.net/p/mingw-w64/mingw-w64/ci/b2302cd60b94a6d68a0e18b3f886b82f4b7f22b7/
in comparison to the march version?
I mean 5325 works for me, 5447 does not.

@lhmouse
Copy link
Contributor

lhmouse commented Jul 14, 2019

It has fixed another deadlock so it will not reverted. If the other patch above fixes this for you, I may check it in as a different commit.

@CoffeeOne
Copy link
Author

Can you give me a hint how to build (and deploy to my MSYS2) a patched libwinpthread?
Then I could test, if it solves the "stockfish hanging" problem or not.

@lhmouse
Copy link
Contributor

lhmouse commented Jul 19, 2019

@CoffeeOne First you should build vanilla mingw-w64-winpthreads-git (see the wiki for detailed instructions). This is necessary to create a working tree for you at mingw-w64-winpthreads-git/src/mingw-w64/. Once you have a working tree, you make changes to files in it, then rebuild the packages by running makepkg-mingw -e (note the -e option; otherwise your modification will be lost) in mingw-w64-winpthreads-git. The packages built have extensions .tar.xz which can be installed using pacman -U.

@CoffeeOne
Copy link
Author

CoffeeOne commented Jul 20, 2019

I was successful in building the library.
After building, I had the issue again.
Then I started changing the file cond.c, leaving everything else unchanged, and did builds with the flags -ef:
Using cond.c from commit 52f2ce12c6182bd239e4f1bbffcd420997b64b08 (Feb 28) makes the problem go away.
Also making a build with cond.c from commit 2a439e13bc37311fa24ca79132900f28902a3e3f and using it to build stockfish worked, so only the build using the latest cond.c was bad.
I then tried to apply the mentioned patch
patch.diff.txt on "latest" There was one conflict, I skipped the conflicted section, but had again a "bad" winpthread library. Then I converted cond.c back to the version from Feb 28, and applied the patch amd built again the winpthread. I made a speed test of 2 stockfish versions one with this self build package and the other built with the official 5325.11a5459d, it ran approx. an hour. Speed was about the same (within error bounds), but it means both versions were 100% stable, with problematic builds hangs occur early (~20 seconds).

@lhmouse
Copy link
Contributor

lhmouse commented Jul 21, 2019

The last commit b2302cd60b94a6d68a0e18b3f886b82f4b7f22b7 cannot be reverted because otherwise LLD would deadlock (see the links in #5610 (comment)).

Would you please provide some stack backtraces so we are able to tell in which function the deadlock occurs ?

@CoffeeOne
Copy link
Author

I managed to attach gdb (when the chess engine already was hanging) to the stockfish.exe process:

attach: No such file or directory.
Attaching to process 5252
[New Thread 5252.0x2e20]
[New Thread 5252.0x1fd0]
[New Thread 5252.0x1fd8]
Reading symbols from C:\msys64\home\peter\gitrepos\stockfish\src\stockfish.exe...
(No debugging symbols found in C:\msys64\home\peter\gitrepos\stockfish\src\stockfish.exe)
(gdb) thread apply all bt

Thread 4 (Thread 5252.0x1fd8):
#0  0x00007fffba01fa71 in ntdll!DbgBreakPoint () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffba04d4db in ntdll!DbgUiRemoteBreakin () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2  0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#3  0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#4  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 3 (Thread 5252.0x1fd0):
#0  0x00007fffba01cbb4 in ntdll!ZwWaitForMultipleObjects () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb7de7ff7 in WaitForMultipleObjectsEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x00007fffb7de7ede in WaitForMultipleObjects () from C:\WINDOWS\System32\KernelBase.dll
#3  0x0000000064941e28 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#4  0x00000000649420e3 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#5  0x00000000649425e5 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#6  0x000000006fd0267c in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#7  0x000000000045d65a in ?? ()
#8  0x000000000042cc91 in ?? ()
#9  0x000000000042c2d1 in ?? ()
#10 0x000000000046be29 in ?? ()
#11 0x0000000000472897 in ?? ()
#12 0x000000000045fd7b in ?? ()
#13 0x000000000045fdd7 in ?? ()
#14 0x000000000045fb3c in ?? ()
#15 0x000000006fd39d01 in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#16 0x0000000064944b42 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#17 0x00007fffb807b04a in msvcrt!_beginthreadex () from C:\WINDOWS\System32\msvcrt.dll
#18 0x00007fffb807b11c in msvcrt!_endthreadex () from C:\WINDOWS\System32\msvcrt.dll
#19 0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#20 0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#21 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 2 (Thread 5252.0x2e20):
#0  0x00007fffba01cbb4 in ntdll!ZwWaitForMultipleObjects () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb7de7ff7 in WaitForMultipleObjectsEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x00007fffb7de7ede in WaitForMultipleObjects () from C:\WINDOWS\System32\KernelBase.dll
#3  0x0000000064941e28 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#4  0x00000000649420e3 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#5  0x00000000649425e5 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#6  0x000000006fd0267c in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#7  0x000000000045d65a in ?? ()
#8  0x000000000042cc91 in ?? ()
#9  0x000000000042c2d1 in ?? ()
#10 0x000000000046be29 in ?? ()
#11 0x0000000000472897 in ?? ()
#12 0x000000000045fd7b in ?? ()
#13 0x000000000045fdd7 in ?? ()
#14 0x000000000045fb3c in ?? ()
#15 0x000000006fd39d01 in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#16 0x0000000064944b42 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#17 0x00007fffb807b04a in msvcrt!_beginthreadex () from C:\WINDOWS\System32\msvcrt.dll
#18 0x00007fffb807b11c in msvcrt!_endthreadex () from C:\WINDOWS\System32\msvcrt.dll
#19 0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#20 0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#21 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 1 (Thread 5252.0x16c0):
#0  0x00007fffba01cbb4 in ntdll!ZwWaitForMultipleObjects () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb7de7ff7 in WaitForMultipleObjectsEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x00007fffb7de7ede in WaitForMultipleObjects () from C:\WINDOWS\System32\KernelBase.dll
#3  0x0000000064941e28 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#4  0x00000000649420e3 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#5  0x00000000649425e5 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#6  0x000000006fd0267c in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#7  0x000000000045d65a in ?? ()
#8  0x000000000042cc51 in ?? ()
#9  0x000000000042c1d7 in ?? ()
#10 0x000000000042f25a in ?? ()
#11 0x000000000042f9ac in ?? ()
#12 0x0000000000411f98 in ?? ()
#13 0x000000000040138c in ?? ()
#14 0x00000000004014bb in ?? ()
#15 0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#16 0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#17 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb)

How can I get the function names inisde libwinpthread-1?

@CoffeeOne
Copy link
Author

I am sorry, I "stripped" the stockfish.exe, that makes no sense for debugging:

I tried with a newly compiled exe (no strip):

Attaching to process 3320
[New Thread 3320.0x1b98]
[New Thread 3320.0xf64]
[New Thread 3320.0x220c]
[New Thread 3320.0x1aa4]
[New Thread 3320.0x288c]
[New Thread 3320.0xb90]
Reading symbols from C:\msys64\home\peter\gitrepos\stockfish\src\stockfish.exe...
(gdb) thread apply all bt

Thread 7 (Thread 3320.0xb90):
#0  0x00007fffba01fa71 in ntdll!DbgBreakPoint () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffba04d4db in ntdll!DbgUiRemoteBreakin () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2  0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#3  0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#4  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 6 (Thread 3320.0x288c):
#0  0x00007fffba01cbb4 in ntdll!ZwWaitForMultipleObjects () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb7de7ff7 in WaitForMultipleObjectsEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x00007fffb7de7ede in WaitForMultipleObjects () from C:\WINDOWS\System32\KernelBase.dll
#3  0x0000000064941e28 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#4  0x00000000649420e3 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#5  0x00000000649425e5 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#6  0x000000006fd0267c in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#7  0x000000000045d65a in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex> > (this=0x15a3070, __lock=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:273
#8  0x000000000042cc91 in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex>, Thread::idle_loop()::<lambda()> >(std::unique_lock<Mutex> &, Thread::<lambda()>) (this=0x15a3070, __lock=..., __p=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:282
#9  0x000000000042c2d1 in Thread::idle_loop (this=0x15a3040) at thread.cpp:109
#10 0x000000000046be29 in std::__invoke_impl<void, void (Thread::*)(), Thread*> (__f=@0x159cbb0: (void (Thread::*)(Thread * const)) 0x42c200 <Thread::idle_loop()>, __t=@0x159cba8: 0x15a3040) at C:/msys64/mingw64/include/c++/9.1.0/bits/invoke.h:73
#11 0x0000000000472897 in std::__invoke<void (Thread::*)(), Thread*> (__fn=@0x159cbb0: (void (Thread::*)(Thread * const)) 0x42c200 <Thread::idle_loop()>, __args#0=@0x159cba8: 0x15a3040) at C:/msys64/mingw64/include/c++/9.1.0/bits/invoke.h:95
#12 0x000000000045fd7b in std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> >::_M_invoke<0ull, 1ull> (this=0x159cba8) at C:/msys64/mingw64/include/c++/9.1.0/thread:244
#13 0x000000000045fdd7 in std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> >::operator() (this=0x159cba8) at C:/msys64/mingw64/include/c++/9.1.0/thread:251
#14 0x000000000045fb3c in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> > >::_M_run (this=0x159cba0) at C:/msys64/mingw64/include/c++/9.1.0/thread:195
#15 0x000000006fd39d01 in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#16 0x0000000064944b42 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#17 0x00007fffb807b04a in msvcrt!_beginthreadex () from C:\WINDOWS\System32\msvcrt.dll
#18 0x00007fffb807b11c in msvcrt!_endthreadex () from C:\WINDOWS\System32\msvcrt.dll
#19 0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#20 0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#21 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 5 (Thread 3320.0x1aa4):
#0  0x00007fffba01cbb4 in ntdll!ZwWaitForMultipleObjects () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb7de7ff7 in WaitForMultipleObjectsEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x00007fffb7de7ede in WaitForMultipleObjects () from C:\WINDOWS\System32\KernelBase.dll
#3  0x0000000064941e28 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#4  0x00000000649420e3 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#5  0x00000000649425e5 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#6  0x000000006fd0267c in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#7  0x000000000045d65a in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex> > (this=0x34fd080, __lock=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:273
#8  0x000000000042cc91 in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex>, Thread::idle_loop()::<lambda()> >(std::unique_lock<Mutex> &, Thread::<lambda()>) (this=0x34fd080, __lock=..., __p=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:282
#9  0x000000000042c2d1 in Thread::idle_loop (this=0x34fd050) at thread.cpp:109
#10 0x000000000046be29 in std::__invoke_impl<void, void (Thread::*)(), Thread*> (__f=@0x15973f0: (void (Thread::*)(Thread * const)) 0x42c200 <Thread::idle_loop()>, __t=@0x15973e8: 0x34fd050) at C:/msys64/mingw64/include/c++/9.1.0/bits/invoke.h:73
#11 0x0000000000472897 in std::__invoke<void (Thread::*)(), Thread*> (__fn=@0x15973f0: (void (Thread::*)(Thread * const)) 0x42c200 <Thread::idle_loop()>, __args#0=@0x15973e8: 0x34fd050) at C:/msys64/mingw64/include/c++/9.1.0/bits/invoke.h:95
#12 0x000000000045fd7b in std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> >::_M_invoke<0ull, 1ull> (this=0x15973e8) at C:/msys64/mingw64/include/c++/9.1.0/thread:244
#13 0x000000000045fdd7 in std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> >::operator() (this=0x15973e8) at C:/msys64/mingw64/include/c++/9.1.0/thread:251
#14 0x000000000045fb3c in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> > >::_M_run (this=0x15973e0) at C:/msys64/mingw64/include/c++/9.1.0/thread:195
#15 0x000000006fd39d01 in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#16 0x0000000064944b42 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#17 0x00007fffb807b04a in msvcrt!_beginthreadex () from C:\WINDOWS\System32\msvcrt.dll
#18 0x00007fffb807b11c in msvcrt!_endthreadex () from C:\WINDOWS\System32\msvcrt.dll
#19 0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#20 0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#21 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 4 (Thread 3320.0x220c):
#0  0x00007fffba01f9f4 in ntdll!ZwWaitForWorkViaWorkerFactory () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb9fb3ff0 in ntdll!RtlInitializeResource () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2  0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#3  0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#4  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 3 (Thread 3320.0xf64):
#0  0x00007fffba01f9f4 in ntdll!ZwWaitForWorkViaWorkerFactory () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb9fb3ff0 in ntdll!RtlInitializeResource () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2  0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#3  0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#4  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 2 (Thread 3320.0x1b98):
#0  0x00007fffba01f9f4 in ntdll!ZwWaitForWorkViaWorkerFactory () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb9fb3ff0 in ntdll!RtlInitializeResource () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2  0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#3  0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#4  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 1 (Thread 3320.0x1c6c):
#0  0x00007fffba01cbb4 in ntdll!ZwWaitForMultipleObjects () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb7de7ff7 in WaitForMultipleObjectsEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x00007fffb7de7ede in WaitForMultipleObjects () from C:\WINDOWS\System32\KernelBase.dll
#3  0x0000000064941e28 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#4  0x00000000649420e3 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#5  0x00000000649425e5 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#6  0x000000006fd0267c in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#7  0x000000000045d65a in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex> > (this=0x15a3070, __lock=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:273
#8  0x000000000042cc51 in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex>, Thread::wait_for_search_finished()::<lambda()> >(std::unique_lock<Mutex> &, Thread::<lambda()>) (this=0x15a3070, __lock=..., __p=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:282
#9  0x000000000042c1d7 in Thread::wait_for_search_finished (this=0x15a3040) at thread.cpp:87
#10 0x000000000042f25a in (anonymous namespace)::bench (pos=..., args=..., states=...) at uci.cpp:162
#11 0x000000000042f9ac in UCI::loop (argc=2, argv=0x15916f0) at uci.cpp:234
#12 0x0000000000411f98 in main (argc=2, argv=0x15916f0) at main.cpp:50
(gdb)

@CoffeeOne
Copy link
Author

and a second hang, looks similar:

Type "apropos word" to search for commands related to "word"...
attach: No such file or directory.
Attaching to process 1128
[New Thread 1128.0x2ed0]
[New Thread 1128.0x26a4]
[New Thread 1128.0x1a94]
[New Thread 1128.0xfb8]
[New Thread 1128.0x2760]
[New Thread 1128.0x1700]
Reading symbols from C:\msys64\home\peter\gitrepos\stockfish\src\stockfish.exe...
(gdb) thread apply all bt

Thread 7 (Thread 1128.0x1700):
#0  0x00007fffba01fa71 in ntdll!DbgBreakPoint () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffba04d4db in ntdll!DbgUiRemoteBreakin () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2  0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#3  0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#4  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 6 (Thread 1128.0x2760):
#0  0x00007fffba01cbb4 in ntdll!ZwWaitForMultipleObjects () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb7de7ff7 in WaitForMultipleObjectsEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x00007fffb7de7ede in WaitForMultipleObjects () from C:\WINDOWS\System32\KernelBase.dll
#3  0x0000000064941e28 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#4  0x00000000649420e3 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#5  0x00000000649425e5 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#6  0x000000006fd0267c in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#7  0x000000000045d65a in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex> > (this=0x1716070, __lock=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:273
#8  0x000000000042cc91 in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex>, Thread::idle_loop()::<lambda()> >(std::unique_lock<Mutex> &, Thread::<lambda()>) (this=0x1716070, __lock=..., __p=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:282
#9  0x000000000042c2d1 in Thread::idle_loop (this=0x1716040) at thread.cpp:109
#10 0x000000000046be29 in std::__invoke_impl<void, void (Thread::*)(), Thread*> (__f=@0x170c8b0: (void (Thread::*)(Thread * const)) 0x42c200 <Thread::idle_loop()>, __t=@0x170c8a8: 0x1716040) at C:/msys64/mingw64/include/c++/9.1.0/bits/invoke.h:73
#11 0x0000000000472897 in std::__invoke<void (Thread::*)(), Thread*> (__fn=@0x170c8b0: (void (Thread::*)(Thread * const)) 0x42c200 <Thread::idle_loop()>, __args#0=@0x170c8a8: 0x1716040) at C:/msys64/mingw64/include/c++/9.1.0/bits/invoke.h:95
#12 0x000000000045fd7b in std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> >::_M_invoke<0ull, 1ull> (this=0x170c8a8) at C:/msys64/mingw64/include/c++/9.1.0/thread:244
#13 0x000000000045fdd7 in std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> >::operator() (this=0x170c8a8) at C:/msys64/mingw64/include/c++/9.1.0/thread:251
#14 0x000000000045fb3c in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> > >::_M_run (this=0x170c8a0) at C:/msys64/mingw64/include/c++/9.1.0/thread:195
#15 0x000000006fd39d01 in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#16 0x0000000064944b42 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#17 0x00007fffb807b04a in msvcrt!_beginthreadex () from C:\WINDOWS\System32\msvcrt.dll
#18 0x00007fffb807b11c in msvcrt!_endthreadex () from C:\WINDOWS\System32\msvcrt.dll
#19 0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#20 0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#21 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 5 (Thread 1128.0xfb8):
#0  0x00007fffba01cbb4 in ntdll!ZwWaitForMultipleObjects () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb7de7ff7 in WaitForMultipleObjectsEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x00007fffb7de7ede in WaitForMultipleObjects () from C:\WINDOWS\System32\KernelBase.dll
#3  0x0000000064941e28 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#4  0x00000000649420e3 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#5  0x00000000649425e5 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#6  0x000000006fd0267c in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#7  0x000000000045d65a in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex> > (this=0x3666080, __lock=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:273
#8  0x000000000042cc91 in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex>, Thread::idle_loop()::<lambda()> >(std::unique_lock<Mutex> &, Thread::<lambda()>) (this=0x3666080, __lock=..., __p=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:282
#9  0x000000000042c2d1 in Thread::idle_loop (this=0x3666050) at thread.cpp:109
#10 0x000000000046be29 in std::__invoke_impl<void, void (Thread::*)(), Thread*> (__f=@0x17073f0: (void (Thread::*)(Thread * const)) 0x42c200 <Thread::idle_loop()>, __t=@0x17073e8: 0x3666050) at C:/msys64/mingw64/include/c++/9.1.0/bits/invoke.h:73
#11 0x0000000000472897 in std::__invoke<void (Thread::*)(), Thread*> (__fn=@0x17073f0: (void (Thread::*)(Thread * const)) 0x42c200 <Thread::idle_loop()>, __args#0=@0x17073e8: 0x3666050) at C:/msys64/mingw64/include/c++/9.1.0/bits/invoke.h:95
#12 0x000000000045fd7b in std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> >::_M_invoke<0ull, 1ull> (this=0x17073e8) at C:/msys64/mingw64/include/c++/9.1.0/thread:244
#13 0x000000000045fdd7 in std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> >::operator() (this=0x17073e8) at C:/msys64/mingw64/include/c++/9.1.0/thread:251
#14 0x000000000045fb3c in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> > >::_M_run (this=0x17073e0) at C:/msys64/mingw64/include/c++/9.1.0/thread:195
#15 0x000000006fd39d01 in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#16 0x0000000064944b42 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#17 0x00007fffb807b04a in msvcrt!_beginthreadex () from C:\WINDOWS\System32\msvcrt.dll
#18 0x00007fffb807b11c in msvcrt!_endthreadex () from C:\WINDOWS\System32\msvcrt.dll
#19 0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#20 0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#21 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 4 (Thread 1128.0x1a94):
#0  0x00007fffba01f9f4 in ntdll!ZwWaitForWorkViaWorkerFactory () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb9fb3ff0 in ntdll!RtlInitializeResource () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2  0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#3  0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#4  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 3 (Thread 1128.0x26a4):
#0  0x00007fffba01f9f4 in ntdll!ZwWaitForWorkViaWorkerFactory () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb9fb3ff0 in ntdll!RtlInitializeResource () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2  0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#3  0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#4  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 2 (Thread 1128.0x2ed0):
#0  0x00007fffba01f9f4 in ntdll!ZwWaitForWorkViaWorkerFactory () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb9fb3ff0 in ntdll!RtlInitializeResource () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2  0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#3  0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#4  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 1 (Thread 1128.0x29cc):
#0  0x00007fffba01cbb4 in ntdll!ZwWaitForMultipleObjects () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb7de7ff7 in WaitForMultipleObjectsEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x00007fffb7de7ede in WaitForMultipleObjects () from C:\WINDOWS\System32\KernelBase.dll
#3  0x0000000064941e28 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#4  0x00000000649420e3 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#5  0x00000000649425e5 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#6  0x000000006fd0267c in ?? () from C:\msys64\mingw64\bin\libstdc++-6.dll
#7  0x000000000045d65a in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex> > (this=0x1716070, __lock=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:273
#8  0x000000000042cc51 in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex>, Thread::wait_for_search_finished()::<lambda()> >(std::unique_lock<Mutex> &, Thread::<lambda()>) (this=0x1716070, __lock=..., __p=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:282
#9  0x000000000042c1d7 in Thread::wait_for_search_finished (this=0x1716040) at thread.cpp:87
#10 0x000000000042f25a in (anonymous namespace)::bench (pos=..., args=..., states=...) at uci.cpp:162
#11 0x000000000042f9ac in UCI::loop (argc=2, argv=0x17016f0) at uci.cpp:234
#12 0x0000000000411f98 in main (argc=2, argv=0x17016f0) at main.cpp:50
(gdb)

@oscarfv
Copy link
Contributor

oscarfv commented Jul 21, 2019

@CoffeeOne : on the PKGBUILD of winpthreads change the line:

options=('strip' '!buildflags' 'staticlibs' '!emptydirs' '!debug')

to

options=('!strip' '!buildflags' 'staticlibs' '!emptydirs' 'debug')

and then rebuild the package.

@CoffeeOne
Copy link
Author

Thx, I rebuild the winpthread (no changes in cond.c!)
and build a new stockfish binary and let it hang:

Attaching to process 2132
[New Thread 2132.0x1c78]
[New Thread 2132.0x2328]
[New Thread 2132.0xf44]
[New Thread 2132.0x253c]
Reading symbols from C:\msys64\home\peter\gitrepos\stockfish\src\stockfish.exe...
(gdb) thread apply all bt

Thread 5 (Thread 2132.0x253c):
#0  0x00007fffba01fa71 in ntdll!DbgBreakPoint () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffba04d4db in ntdll!DbgUiRemoteBreakin () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2  0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#3  0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#4  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 4 (Thread 2132.0xf44):
#0  0x00007fffba01cbb4 in ntdll!ZwWaitForMultipleObjects () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb7de7ff7 in WaitForMultipleObjectsEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x00007fffb7de7ede in WaitForMultipleObjects () from C:\WINDOWS\System32\KernelBase.dll
#3  0x0000000000455337 in _pthread_wait_for_multiple_objects (count=2, handles=0x168fac0, all=0, timeout=4294967295) at ../mingw-w64/mingw-w64-libraries/winpthreads/src/misc.c:136
#4  0x0000000000454dc1 in do_sema_b_wait_intern (sema=0x8c, nointerrupt=0, timeout=4294967295) at ../mingw-w64/mingw-w64-libraries/winpthreads/src/cond.c:615
#5  0x0000000000454c8a in do_sema_b_wait (sema=0x8c, nointerrupt=0, timeout=4294967295, cs=0x188f70, val=0x188f98) at ../mingw-w64/mingw-w64-libraries/winpthreads/src/cond.c:574
#6  0x00000000004547c0 in pthread_cond_wait (c=0x127a070, external_mutex=0x18be20) at ../mingw-w64/mingw-w64-libraries/winpthreads/src/cond.c:445
#7  0x00000000004ea4cc in std::condition_variable::wait(std::unique_lock<std::mutex>&) ()
#8  0x00000000004eba6a in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex> > (this=0x127a070, __lock=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:273
#9  0x000000000042cc91 in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex>, Thread::idle_loop()::<lambda()> >(std::unique_lock<Mutex> &, Thread::<lambda()>) (this=0x127a070, __lock=..., __p=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:282
#10 0x000000000042c2d1 in Thread::idle_loop (this=0x127a040) at thread.cpp:109
#11 0x00000000005174f9 in std::__invoke_impl<void, void (Thread::*)(), Thread*> (__f=@0x18c820: (void (Thread::*)(Thread * const)) 0x42c200 <Thread::idle_loop()>, __t=@0x18c818: 0x127a040) at C:/msys64/mingw64/include/c++/9.1.0/bits/invoke.h:73
#12 0x0000000000520697 in std::__invoke<void (Thread::*)(), Thread*> (__fn=@0x18c820: (void (Thread::*)(Thread * const)) 0x42c200 <Thread::idle_loop()>, __args#0=@0x18c818: 0x127a040) at C:/msys64/mingw64/include/c++/9.1.0/bits/invoke.h:95
#13 0x00000000004f167b in std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> >::_M_invoke<0ull, 1ull> (this=0x18c818) at C:/msys64/mingw64/include/c++/9.1.0/thread:244
#14 0x00000000004f16d7 in std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> >::operator() (this=0x18c818) at C:/msys64/mingw64/include/c++/9.1.0/thread:251
#15 0x00000000004f11bc in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> > >::_M_run (this=0x18c810) at C:/msys64/mingw64/include/c++/9.1.0/thread:195
#16 0x00000000005280e1 in execute_native_thread_routine ()
#17 0x0000000000458a7d in pthread_create_wrapper (args=0x18b290) at ../mingw-w64/mingw-w64-libraries/winpthreads/src/thread.c:1499
#18 0x00007fffb807b04a in msvcrt!_beginthreadex () from C:\WINDOWS\System32\msvcrt.dll
#19 0x00007fffb807b11c in msvcrt!_endthreadex () from C:\WINDOWS\System32\msvcrt.dll
#20 0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#21 0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#22 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 3 (Thread 2132.0x2328):
#0  0x00007fffba01cbb4 in ntdll!ZwWaitForMultipleObjects () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb7de7ff7 in WaitForMultipleObjectsEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x00007fffb7de7ede in WaitForMultipleObjects () from C:\WINDOWS\System32\KernelBase.dll
#3  0x0000000000455337 in _pthread_wait_for_multiple_objects (count=2, handles=0x35cfac0, all=0, timeout=4294967295) at ../mingw-w64/mingw-w64-libraries/winpthreads/src/misc.c:136
#4  0x0000000000454dc1 in do_sema_b_wait_intern (sema=0xa4, nointerrupt=0, timeout=4294967295) at ../mingw-w64/mingw-w64-libraries/winpthreads/src/cond.c:615
#5  0x0000000000454c8a in do_sema_b_wait (sema=0xa4, nointerrupt=0, timeout=4294967295, cs=0x189c30, val=0x189c58) at ../mingw-w64/mingw-w64-libraries/winpthreads/src/cond.c:574
#6  0x00000000004547c0 in pthread_cond_wait (c=0x31b7080, external_mutex=0x18bd80) at ../mingw-w64/mingw-w64-libraries/winpthreads/src/cond.c:445
#7  0x00000000004ea4cc in std::condition_variable::wait(std::unique_lock<std::mutex>&) ()
#8  0x00000000004eba6a in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex> > (this=0x31b7080, __lock=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:273
#9  0x000000000042cc91 in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex>, Thread::idle_loop()::<lambda()> >(std::unique_lock<Mutex> &, Thread::<lambda()>) (this=0x31b7080, __lock=..., __p=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:282
#10 0x000000000042c2d1 in Thread::idle_loop (this=0x31b7050) at thread.cpp:109
#11 0x00000000005174f9 in std::__invoke_impl<void, void (Thread::*)(), Thread*> (__f=@0x186e90: (void (Thread::*)(Thread * const)) 0x42c200 <Thread::idle_loop()>, __t=@0x186e88: 0x31b7050) at C:/msys64/mingw64/include/c++/9.1.0/bits/invoke.h:73
#12 0x0000000000520697 in std::__invoke<void (Thread::*)(), Thread*> (__fn=@0x186e90: (void (Thread::*)(Thread * const)) 0x42c200 <Thread::idle_loop()>, __args#0=@0x186e88: 0x31b7050) at C:/msys64/mingw64/include/c++/9.1.0/bits/invoke.h:95
#13 0x00000000004f167b in std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> >::_M_invoke<0ull, 1ull> (this=0x186e88) at C:/msys64/mingw64/include/c++/9.1.0/thread:244
#14 0x00000000004f16d7 in std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> >::operator() (this=0x186e88) at C:/msys64/mingw64/include/c++/9.1.0/thread:251
#15 0x00000000004f11bc in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (Thread::*)(), Thread*> > >::_M_run (this=0x186e80) at C:/msys64/mingw64/include/c++/9.1.0/thread:195
#16 0x00000000005280e1 in execute_native_thread_routine ()
#17 0x0000000000458a7d in pthread_create_wrapper (args=0x18b4c0) at ../mingw-w64/mingw-w64-libraries/winpthreads/src/thread.c:1499
#18 0x00007fffb807b04a in msvcrt!_beginthreadex () from C:\WINDOWS\System32\msvcrt.dll
#19 0x00007fffb807b11c in msvcrt!_endthreadex () from C:\WINDOWS\System32\msvcrt.dll
#20 0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#21 0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#22 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 2 (Thread 2132.0x1c78):
#0  0x00007fffba01f9f4 in ntdll!ZwWaitForWorkViaWorkerFactory () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb9fb3ff0 in ntdll!RtlInitializeResource () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2  0x00007fffb89d7bd4 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#3  0x00007fffb9fece71 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#4  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 1 (Thread 2132.0x2a28):
#0  0x00007fffba01cbb4 in ntdll!ZwWaitForMultipleObjects () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007fffb7de7ff7 in WaitForMultipleObjectsEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x00007fffb7de7ede in WaitForMultipleObjects () from C:\WINDOWS\System32\KernelBase.dll
#3  0x0000000000455337 in _pthread_wait_for_multiple_objects (count=2, handles=0xe0edd0, all=0, timeout=4294967295) at ../mingw-w64/mingw-w64-libraries/winpthreads/src/misc.c:136
#4  0x0000000000454dc1 in do_sema_b_wait_intern (sema=0x8c, nointerrupt=0, timeout=4294967295) at ../mingw-w64/mingw-w64-libraries/winpthreads/src/cond.c:615
#5  0x0000000000454c8a in do_sema_b_wait (sema=0x8c, nointerrupt=0, timeout=4294967295, cs=0x188f70, val=0x188f98) at ../mingw-w64/mingw-w64-libraries/winpthreads/src/cond.c:574
#6  0x00000000004547c0 in pthread_cond_wait (c=0x127a070, external_mutex=0x18be20) at ../mingw-w64/mingw-w64-libraries/winpthreads/src/cond.c:445
#7  0x00000000004ea4cc in std::condition_variable::wait(std::unique_lock<std::mutex>&) ()
#8  0x00000000004eba6a in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex> > (this=0x127a070, __lock=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:273
#9  0x000000000042cc51 in std::_V2::condition_variable_any::wait<std::unique_lock<Mutex>, Thread::wait_for_search_finished()::<lambda()> >(std::unique_lock<Mutex> &, Thread::<lambda()>) (this=0x127a070, __lock=..., __p=...) at C:/msys64/mingw64/include/c++/9.1.0/condition_variable:282
#10 0x000000000042c1d7 in Thread::wait_for_search_finished (this=0x127a040) at thread.cpp:87
#11 0x000000000042f25a in (anonymous namespace)::bench (pos=..., args=..., states=...) at uci.cpp:162
#12 0x000000000042f9ac in UCI::loop (argc=2, argv=0x1813c0) at uci.cpp:234
#13 0x0000000000411f98 in main (argc=2, argv=0x1813c0) at main.cpp:50

@lhmouse
Copy link
Contributor

lhmouse commented Jul 22, 2019

It seems that at least a call to wakeup functions was missed.

Could you provide a self-contained test program that consists of only one file please?

@ppigazzini
Copy link

@CoffeeOne I suggest to rename the issue in something more meaningful like this "winpthreads bug with stockfish". Great catch!

@CoffeeOne CoffeeOne changed the title Compiling chess engine stockfish with gcc 9.1.0 Rev.3 Compiling chess engine stockfish with MSYS2 using mingw-w64-x86_64-libwinpthread-git-7.0.0.5447 (and later versions) Sep 15, 2019
@CoffeeOne
Copy link
Author

CoffeeOne commented Sep 21, 2019

@lhmouse
I now tested with a local build of mingw-w64-winpthreads-git (no files changed!): I created
mingw-w64-x86_64-libwinpthread-git-7.0.0.5535.0128fb46-1-any.pkg.tar.xz mingw-w64-x86_64-winpthreads-git-7.0.0.5535.0128fb46-1-any.pkg.tar.xz and used it for building stockfish.
That made the problem go away, I did not see hangs anymore.

@ppigazzini
Copy link

@CoffeeOne the latest msys2 update seems to have solved this bug. Here are my tests official-stockfish/Stockfish#2305 (comment) , please confirm with some tests on your pc.

@CoffeeOne
Copy link
Author

@ppigazzini
I confirm that with the official version
7.0.0.5544.15da3ce2-1 problem is solved for me, too!
thx again @lhmouse 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants