critter-mj / akochan

Artificial Intelligence for Japanese mahjong
Other
244 stars 38 forks source link

Thread race condition issue when running with MSYS2 on Windows #27

Closed SethRobinson closed 2 weeks ago

SethRobinson commented 2 weeks ago

Great program! Works fine on Ubuntu, but not on Windows.

I get segfault doing anything with it built with Msys2 MinGW64 on Windows.

$ gdb system.exe
GNU gdb (GDB) 15.2
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <[http://gnu.org/licenses/gpl.html>](http://gnu.org/licenses/gpl.html%3E)
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<[https://www.gnu.org/software/gdb/bugs/>](https://www.gnu.org/software/gdb/bugs/%3E).
Find the GDB manual and other documentation resources online at:
    <[http://www.gnu.org/software/gdb/documentation/>](http://www.gnu.org/software/gdb/documentation/%3E).
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from system.exe...
(gdb) run test 1 2
Starting program: D:\projects\Mahjong\akochan\system.exe test 1 2
[New Thread 57400.0xe570]
[New Thread 57400.0x674]
[New Thread 57400.0x2200]
0 {"aka_flag": true, "kyoku_first": 4, "type": "start_game"}
1 {"bakaze": "E", "dora_marker": "3m", "haiyama": ["7s", "6p", "6m", "9m", "E", "2m", "S", "2p", "9s", "6m", "1s", "N", "5p", "2p", "4m", "2s", "1m", "2p", "1s", "S", "2p", "S", "4p", "5mr", "3p", "4s", "C", "5sr", "E", "5p", "E", "6p", "6p", "1s", "E", "3s", "8s", "7p", "P", "2s", "5s", "8s", "9m", "8p", "6m", "4m", "5pr", "5m", "8m", "6s", "5m", "9m", "P", "F", "2m", "7p", "6m", "7p", "3p", "3s", "7m", "2s", "4p", "7s", "6s", "5m", "3p", "8m", "3p", "4s", "C", "1m", "N", "F", "8p", "1p", "4m", "1p", "1p", "W", "P", "1s", "9s", "5p", "6p", "P", "9p", "W", "9s", "4m", "8s", "C", "3s", "3m", "S", "W", "1m", "4p", "9s", "1m", "8p", "6s", "W", "9p", "5s", "7s", "8p", "4s", "7m", "N", "9p", "7m", "2s", "6s", "2m", "1p", "7s", "N", "8m", "3m", "2m", "7m", "C", "F", "F", "5s", "8s", "9p", "3m", "4s", "3m", "8m", "3s", "4p", "9m", "7p"], "honba": 0, "kyoku": 1, "kyotaku": 0, "oya": 0, "scores": [25000, 25000, 25000, 25000], "tehais": [["7s", "E", "9s", "5p", "1m", "2p", "3p", "E", "6p", "8s", "5s", "6m", "8m"], ["6p", "2m", "6m", "2p", "2p", "S", "4s", "5p", "1s", "7p", "8s", "4m", "6s"], ["6m", "S", "1s", "4m", "1s", "4p", "C", "E", "E", "P", "9m", "5pr", "5m"], ["9m", "2p", "N", "2s", "S", "5mr", "5sr", "6p", "3s", "2s", "8p", "5m", "9m"]], "type": "start_kyoku"}
2 {"actor": 0, "pai": "P", "type": "tsumo"}
[New Thread 57400.0xed98]
[New Thread 57400.0xe70]
[New Thread 57400.0x4928]
[New Thread 57400.0x7104]
[New Thread 57400.0x4204]
[New Thread 57400.0xef00]
[New Thread 57400.0xe2c8]
[New Thread 57400.0x9848]
[New Thread 57400.0xecb0]
[New Thread 57400.0x1fa8]
[New Thread 57400.0x8188]
[New Thread 57400.0xd4a0]
[New Thread 57400.0xaad4]
[New Thread 57400.0xe180]
[New Thread 57400.0xcd30]
[New Thread 57400.0xbd04]
[New Thread 57400.0xe4d8]
[New Thread 57400.0xeca4]
[New Thread 57400.0x37c8]
[New Thread 57400.0xc5b8]
[New Thread 57400.0x79f8]
[New Thread 57400.0x700]
[New Thread 57400.0xa928]
Thread 1 received signal SIGSEGV, Segmentation fault.
Tehai_Calculator::set_candidates3_multi_thread (this=0x5a95f0, game_record=..., game_state=...,
    sute_flag=..., tehai_analyzer=..., tactics=...) at tehai_cal.cpp:887
887                                     const Agari_Calc& agari = tehai_calculator_work.agari_graph_work[agari_loc[0]][an];
(gdb)

Anyway, this problem can be worked around by limiting to one thread:

export OMP_NUM_THREADS=1
./system.exe test 1 2

(works fine)

Random thoughts:

SethRobinson commented 2 weeks ago

After rebuilding this as a normal windows console Visual Studio (non-make file) solution it worked correctly - (set at NPROC = 8) Maybe MSYS has limited access to the cores and that's why NPROC at 4 causes segfaults? Not sure, but this might be expected behavior in that case, so I will close this.