{"action":"created","issue":{"url":"https://api.github.com/repos/xbmc/xbmc/issues/6402","labels_url":"https://api.github.com/repos/xbmc/xbmc/issues/6402/labels{/name}","comments_url":"https://api.github.com/repos/xbmc/xbmc/issues/6402/comments","events_url":"https://api.github.com/repos/xbmc/xbmc/issues/6402/events","html_url":"https://github.com/xbmc/xbmc/pull/6402","id":57303523,"number":6402,"title":"Locale fixes","user":{"login":"Karlson2k","id":1898693,"avatar_url":"https://avatars.githubusercontent.com/u/1898693?v=3","gravatar_id":"","url":"https://api.github.com/users/Karlson2k","html_url":"https://github.com/Karlson2k","followers_url":"https://api.github.com/users/Karlson2k/followers","following_url":"https://api.github.com/users/Karlson2k/following{/other_user}","gists_url":"https://api.github.com/users/Karlson2k/gists{/gist_id}","starred_url":"https://api.github.com/users/Karlson2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Karlson2k/subscriptions","organizations_url":"https://api.github.com/users/Karlson2k/orgs","repos_url":"https://api.github.com/users/Karlson2k/repos","events_url":"https://api.github.com/users/Karlson2k/events{/privacy}","received_events_url":"https://api.github.com/users/Karlson2k/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-11T11:20:17Z","updated_at":"2015-02-11T11:22:22Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/xbmc/xbmc/pulls/6402","html_url":"https://github.com/xbmc/xbmc/pull/6402","diff_url":"https://github.com/xbmc/xbmc/pull/6402.diff","patch_url":"https://github.com/xbmc/xbmc/pull/6402.patch"},"body":"The main goal of this PR is fixing crash on Win32.\r\nMS CRT lib is crashed when `setlocale()` is called from multiple threads since VS2012 (for more information see [bug description](https://connect.microsoft.com/VisualStudio/feedback/details/794122) and CRT source code provided with Visual Studio).\r\nCrash can be eliminated by using `_wsetlocale()` instead of `setlocale()` or by calling `_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)` in each thread.\r\nTo minimize chance of crash we need to use both methods, because we can't set thread local locale in externally produced threads (libmicrohttpd, Python) and some external libs use `setlocale()`.\r\nAfter enabled thread local locale, changing GUI regional settings will affect only on one thread. To overcome this `AlphaNumericCompare()` must use locale from g_langInfo. This will also fix bug in `AlphaNumericCompare()` (using reference to temporarily object)."},"comment":{"url":"https://api.github.com/repos/xbmc/xbmc/issues/comments/73866528","html_url":"https://github.com/xbmc/xbmc/pull/6402#issuecomment-73866528","issue_url":"https://api.github.com/repos/xbmc/xbmc/issues/6402","id":73866528,"user":{"login":"Karlson2k","id":1898693,"avatar_url":"https://avatars.githubusercontent.com/u/1898693?v=3","gravatar_id":"","url":"https://api.github.com/users/Karlson2k","html_url":"https://github.com/Karlson2k","followers_url":"https://api.github.com/users/Karlson2k/followers","following_url":"https://api.github.com/users/Karlson2k/following{/other_user}","gists_url":"https://api.github.com/users/Karlson2k/gists{/gist_id}","starred_url":"https://api.github.com/users/Karlson2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Karlson2k/subscriptions","organizations_url":"https://api.github.com/users/Karlson2k/orgs","repos_url":"https://api.github.com/users/Karlson2k/repos","events_url":"https://api.github.com/users/Karlson2k/events{/privacy}","received_events_url":"https://api.github.com/users/Karlson2k/received_events","type":"User","site_admin":false},"created_at":"2015-02-11T11:22:22Z","updated_at":"2015-02-11T11:22:22Z","body":"Test crash program:\r\n```` C++\r\n#include <SDKDDKVer.h>\r\n\r\n#include <Windows.h>\r\n#include <locale.h>\r\n#include <process.h>\r\n\r\n\r\nunsigned int __stdcall threadFunc(void* p)\r\n{\r\n  //_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);\r\n  while (1)\r\n  {\r\n    setlocale(LC_NUMERIC, NULL);\r\n    Sleep(50);\r\n  }\r\n  return 0;\r\n}\r\n\r\n\r\nint wmain(int argc, wchar_t* argv[])\r\n{\r\n  //_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);\r\n  for (int i = 0; i < 20; ++i)\r\n    _beginthreadex(NULL, 0, threadFunc, NULL, 0, NULL);\r\n\r\n  Sleep(60 * 1000);\r\n  return 0;\r\n}\r\n````"}}