更新 2:コードの後のセクションを参照してください。
GMP ライブラリを使用して PI を計算するためのスレッドを使用していますが、wxThread::OnExit()
内部で wxWidgets が呼び出されると、どういうわけかセグメンテーション エラーが発生します。
wxWidgets ソース コードの行は次のとおりです: src/msw/thread.cpp#553
私のスレッドエントリ関数からの短縮コードは次のとおりです。
while (i <= m_numIterations && !TestDestroy()) {
mpf_div(result, perimeter, edgeCount);
mpf_pow_ui(result, result, 2);
mpf_ui_sub(result, 1, result);
mpf_sqrt(result, result);
mpf_div_ui(result, result, 2);
mpf_sub(result, half, result);
mpf_sqrt(result, result);
mpf_mul_ui(result, result, 2);
mpf_mul(result, result, edgeCount);
mpf_set(perimeter, result);
i++;
mpf_mul_ui(edgeCount, edgeCount, 2);
}
// Free GMP variables we don't need anymore
mpf_clear(half);
mpf_clear(result);
mpf_clear(edgeCount);
// OUTPUT_DIGITS has a constant value, e.g. 12
char outputStr[OUTPUT_DIGITS];
mp_exp_t *expptr;
// If commented out, the error does not appear!
mpf_get_str(outputStr, expptr, 10, OUTPUT_DIGITS, perimeter);
更新 2:で最後の行をコメントアウトするとmpf_get_str()
、エラーは発生しません。
2003 年からの非常に古いバグ リクエストも見つけました: http://gmplib.org/list-archives/gmp-discuss/2003-November/000888.html
GCC デバッガーからのコール スタック:
#0 63AE80E9 wxThreadInternal::DoThreadOnExit(thread=0x2cfa978) (../../src/msw/thread.cpp:553)
#1 63B27ACF wxScopeGuardImpl1<void (*)(wxThread*) (../../include/wx/scopeguard.h:168)
#2 63B3F95B wxPrivate::OnScopeExit<wxScopeGuardImpl1<void (*)(wxThread*) (../../include/wx/scopeguard.h:67)
#3 63B27B36 wxScopeGuardImpl1<void (*)(wxThread*) (../../include/wx/scopeguard.h:166)
#4 63AE82FB wxThreadInternal::DoThreadStart(thread=0x2cfa978) (../../src/msw/thread.cpp:561)
#5 63AE83F2 wxThreadInternal::WinThreadStart(param=0x2cfa978) (../../src/msw/thread.cpp:602)
#6 75C4906A ui64tow() (C:\Windows\SysWOW64\msvcrt.dll:??)
#7 75C49147 msvcrt!iswalnum() (C:\Windows\SysWOW64\msvcrt.dll:??)
#8 76448543 UnregisterBadMemoryNotification() (C:\Windows\SysWOW64\kernel32.dll:??)
#9 00000000 0x02cfb178 in ??() (??:??)
#10 00000000 0x77e8ac69 in ??() (??:??)
#11 00000000 0x77e8ac3c in ??() (??:??)
#12 00000000 0x00000000 in ??() (??:??)