10

setlocale(LC_ALL, "uk-UA") sometimes hangs/deadlocks for me with unknown reason. Call stack is:

ntdll.dll!_ZwWaitForSingleObject@12()   Unknown
ntdll.dll!_RtlpWaitOnCriticalSection@8()    Unknown
ntdll.dll!_RtlEnterCriticalSection@4()  Unknown
ntdll.dll!_LdrpLoadDll@28() Unknown
ntdll.dll!_LdrLoadDll@16()  Unknown
KernelBase.dll!_LoadLibraryExW@12() Unknown
ucrtbased.dll!__crt_findfile_traits::get_invalid_value(void)    Unknown
ucrtbased.dll!__acrt_lock_and_call<class <lambda_a463b7b0560cfcaf9b17f27c6ef46564> >(enum __acrt_lock_id,class <lambda_a463b7b0560cfcaf9b17f27c6ef46564> &&)    Unknown
ucrtbased.dll!__acrt_lock_and_call<class <lambda_a463b7b0560cfcaf9b17f27c6ef46564> >(enum __acrt_lock_id,class <lambda_a463b7b0560cfcaf9b17f27c6ef46564> &&)    Unknown
ucrtbased.dll!__acrt_lock_and_call<class <lambda_a463b7b0560cfcaf9b17f27c6ef46564> >(enum __acrt_lock_id,class <lambda_a463b7b0560cfcaf9b17f27c6ef46564> &&)    Unknown
ucrtbased.dll!__acrt_lock_and_call<class <lambda_a463b7b0560cfcaf9b17f27c6ef46564> >(enum __acrt_lock_id,class <lambda_a463b7b0560cfcaf9b17f27c6ef46564> &&)    Unknown
ucrtbased.dll!__acrt_lock_and_call<class <lambda_a463b7b0560cfcaf9b17f27c6ef46564> >(enum __acrt_lock_id,class <lambda_a463b7b0560cfcaf9b17f27c6ef46564> &&)    Unknown
ucrtbased.dll!___acrt_can_use_vista_locale_apis()   Unknown
ucrtbased.dll!__expandlocale()  Unknown
ucrtbased.dll!__wsetlocale()    Unknown
ucrtbased.dll!__crt_call_and_cleanup<class <lambda_565169b3e3b494427ce1bebdd17b54ac>,class <lambda_f51fe5fd7c79a33db34fc9310f277369> >(class <lambda_565169b3e3b494427ce1bebdd17b54ac> &&,class <lambda_f51fe5fd7c79a33db34fc9310f277369> &&)   Unknown
ucrtbased.dll!__crt_seh_guarded_call<void>::operator()<class <lambda_0f92d0c5a8007722f95b3b6c71cd8e3e>,class <lambda_321f9d61c14d59ff00145e45db1313e0> &,class <lambda_3298c911d7b53f44106027a7fde9a80a> >(class <lambda_0f92d0c5a8007722f95b3b6c71cd8e3e> &&,class <lambda_321f9d61c14d59ff00145e45db1313e0> &,class <lambda_3298c911d7b53f44106027a7fde9a80a> &&) Unknown
ucrtbased.dll!__acrt_lock_and_call<class <lambda_321f9d61c14d59ff00145e45db1313e0> >(enum __acrt_lock_id,class <lambda_321f9d61c14d59ff00145e45db1313e0> &&)    Unknown
ucrtbased.dll!__crt_call_and_cleanup<class <lambda_565169b3e3b494427ce1bebdd17b54ac>,class <lambda_f51fe5fd7c79a33db34fc9310f277369> >(class <lambda_565169b3e3b494427ce1bebdd17b54ac> &&,class <lambda_f51fe5fd7c79a33db34fc9310f277369> &&)   Unknown
ucrtbased.dll!__crt_seh_guarded_call<void>::operator()<class <lambda_507d9fd6b66e39451a8852ba73f804a7>,class <lambda_565169b3e3b494427ce1bebdd17b54ac> &,class <lambda_f51fe5fd7c79a33db34fc9310f277369> &>(class <lambda_507d9fd6b66e39451a8852ba73f804a7> &&,class <lambda_565169b3e3b494427ce1bebdd17b54ac> &,class <lambda_f51fe5fd7c79a33db34fc9310f277369> &) Unknown
ucrtbased.dll!__crt_call_and_cleanup<class <lambda_565169b3e3b494427ce1bebdd17b54ac>,class <lambda_f51fe5fd7c79a33db34fc9310f277369> >(class <lambda_565169b3e3b494427ce1bebdd17b54ac> &&,class <lambda_f51fe5fd7c79a33db34fc9310f277369> &&)   Unknown
ucrtbased.dll!__wsetlocale()    Unknown
ucrtbased.dll!___acrt_update_multibyte_info()   Unknown
ucrtbased.dll!_setlocale()  Unknown

Sometimes it works but sometimes it never returns from it. I can not identify the reason. I use Visual Studio 2015 and Windows 7.

rustyx
  • 80,671
  • 25
  • 200
  • 267
V_V
  • 612
  • 9
  • 23
  • 3
    You left out the bottom part of the call stack, so we cannot see where you are calling `setlocale` from. Since you are running into a loader lock deadlock, are you maybe calling `setlocale` from `DllMain`? – IInspectable Feb 23 '16 at 13:27
  • Oh my! 4 hours later I finally hit the correct search term. Seems I'm hitting the same bug with a slightly different call stack on a Win7 machine. (`ucrtbase.dll` `10.0.10240.16390 (th1_st1.150714-1601)`) – Martin Ba Feb 07 '19 at 15:45

1 Answers1

14

This was a bug in the TH1 build (10.0.10240) of the Universal CRT. The bug was fixed in the Windows 10 November Update (TH2) build (10.0.10586).

You can download and install the updated Windows 10 SDK from https://dev.windows.com/en-us/downloads/windows-10-sdk. This SDK contains the static Universal CRT libraries, the debug Universal CRT DLLs (ucrtbased.dll et al.), and the retail Universal CRT DLLs for app-local redistribution.

You can download the updated Universal CRT redistributables from https://www.microsoft.com/en-us/download/details.aspx?id=50410. These contain the updated retail Universal CRT for central deployment in the system directory.

James McNellis
  • 348,265
  • 75
  • 913
  • 977
  • 1
    James: Can you take a quick peek at: http://stackoverflow.com/questions/37196005/cl-exe-hangs-indefinitely-while-being-invoked-via-msbuild Following your suggestion I have installed KB3118401 applicable for Windows 7 SP1. My confusion is it has now created a "10" folder under "%programfiles%\Windows Kits". Should I be linking my application against the ucrt installed on **this** folder? This is a bit confusing :-( – ForeverLearning May 13 '16 at 13:55
  • 3
    How do I use this UCRT from Visual Studio 2015? Even after installing VS update 2 and Win 10 SDK TH2, it is still linking in UCRT 10.0.10240 (I'm using static CRT mode /MT). – rustyx May 24 '16 at 13:12
  • Let's say I have Windows 10 LTSB verion 1507 (RTM). How can I get this bug fixed in the Universal CRT? Is the only option to update to LTSB version 1607? – Michael Podlejska Apr 21 '17 at 13:15