Share via


_configthreadlocale

스레드별 로캘 옵션을 구성합니다.

구문

int _configthreadlocale( int per_thread_locale_type );

매개 변수

per_thread_locale_type
설정할 옵션입니다. 다음 표에 나열된 옵션 중 하나입니다.

반환 값

이전 per-thread locale 상태(_DISABLE_PER_THREAD_LOCALE 또는 _ENABLE_PER_THREAD_LOCALE), 실패 시 -1을 반환합니다.

설명

_configthreadlocale 함수는 스레드 관련 로캘 사용을 제어하는 데 사용됩니다. 다음 per_thread_locale_type 옵션 중 하나를 사용하여 스레드별 로캘 상태 지정하거나 결정합니다.

옵션 설명
_ENABLE_PER_THREAD_LOCALE 현재 스레드에서 스레드 관련 로캘을 사용하도록 합니다. 이 스레드에서 setlocale에 대한 후속 호출은 스레드 자체의 로캘에만 영향을 줍니다.
_DISABLE_PER_THREAD_LOCALE 현재 스레드에서 전역 로캘을 사용하도록 합니다. 이 스레드에서 setlocale에 대한 후속 호출은 전역 로캘을 사용하는 다른 스레드에 영향을 줍니다.
0 이 특정 스레드에 대한 현재 설정을 검색합니다.

이러한 함수는 , 및 .의 setlocale동작에 _wsetlocale영향을 줍니다._setmbcp_tsetlocale 스레드별 로캘을 사용하지 않도록 설정하면 전역 로캘을 setlocale 사용하는 모든 스레드의 로캘을 후속 호출하거나 _wsetlocale 변경합니다. per-thread locale이 사용되는 경우 setlocale 또는 _wsetlocale만 현재 스레드의 로캘에 영향을 줍니다.

스레드별 로캘을 사용하도록 설정하는 데 사용하는 _configthreadlocale 경우 해당 스레드에 대한 호출 또는 _wsetlocale호출을 통해 즉시 해당 스레드에서 기본 로캘을 setlocale 설정합니다.

테이블에 나열된 값 중 하나가 아닌 경우 per_thread_locale_type 이 함수는 매개 변수 유효성 검사에 설명된 대로 잘못된 매개 변수 처리기를 호출합니다. 계속해서 실행하도록 허용한 경우 이 함수는 errnoEINVAL 로 설정하고 -1을 반환합니다.

기본적으로 이 함수의 전역 상태는 애플리케이션으로 범위가 지정됩니다. 이 동작을 변경하려면 CRT의 전역 상태를 참조하세요.

요구 사항

루틴에서 반환된 값 필수 헤더
_configthreadlocale '<locale.h>'

예시

// crt_configthreadlocale.cpp
//
// This program demonstrates the use of _configthreadlocale when
// using two independent threads.
//
// Compile by using: cl /EHsc /W4 crt_configthreadlocale.cpp

#include <locale.h>
#include <mbctype.h>
#include <process.h>
#include <windows.h>
#include <stdio.h>
#include <time.h>

#define BUFF_SIZE 100

// Retrieve the date and time in the current
// locale's format.
int get_time(unsigned char* str)
{
    __time64_t  ltime;
    struct tm   thetime;

    // Retieve the time
    _time64(&ltime);
    _gmtime64_s(&thetime, &ltime);

    // Format the current time structure into a string
    // using %#x is the long date representation,
    // appropriate to the current locale
    if (!strftime((char *)str, BUFF_SIZE, "%#x",
                  (const struct tm*)&thetime))
    {
        printf("strftime failed!\n");
        return -1;
    }
    return 0;
}

// This thread sets its locale to German
// and prints the time.
unsigned __stdcall SecondThreadFunc( void* /*pArguments*/ )
{
    unsigned char str[BUFF_SIZE];

    _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);

    // Set the thread code page
    _setmbcp(_MB_CP_ANSI);

    // Set the thread locale
    printf("The thread locale is now set to %s.\n",
           setlocale(LC_ALL, "German"));

    // Retrieve the time string from the helper function
    if (get_time(str) == 0)
    {
        printf("The time in German locale is: '%s'\n", str);
    }

    _endthreadex( 0 );
    return 0;
}

// The main thread spawns a second thread (above) and then
// sets the locale to English and prints the time.
int main()
{
    HANDLE          hThread;
    unsigned        threadID;
    unsigned char   str[BUFF_SIZE];

    // Enable per-thread locale causes all subsequent locale
    // setting changes in this thread to only affect this thread.
    _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);

    // Retrieve the time string from the helper function
    printf("The thread locale is now set to %s.\n",
           setlocale(LC_ALL, "English"));

    // Create the second thread.
    hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc,
                                      NULL, 0, &threadID );

    if (get_time(str) == 0)
    {
        // Retrieve the time string from the helper function
        printf("The time in English locale is: '%s'\n\n", str);
    }

    // Wait for the created thread to finish.
    WaitForSingleObject( hThread, INFINITE );

    // Destroy the thread object.
    CloseHandle( hThread );
}
The thread locale is now set to English_United States.1252.
The time in English locale is: 'Wednesday, May 12, 2004'

The thread locale is now set to German_Germany.1252.
The time in German locale is: 'Mittwoch, 12. Mai 2004'

참고 항목

setlocale, _wsetlocale
_beginthread, _beginthreadex
Locale
다중 스레딩 및 로캘