Compartilhar via


_configthreadlocale

Configura as opções de localidade por thread.

int _configthreadlocale(
   int type
);

Parâmetros

  • type
    As opções para conjunto ou opção.Uma das opções listadas na tabela a seguir.

Valor de retorno

O status de localidade por thread anterior (_DISABLE_PER_THREAD_LOCALE ou _ENABLE_PER_THREAD_LOCALE), ou -1 em caso de falha.

Comentários

The _configurethreadlocale função é usada para controlar o uso de thread-localidades específicas.

  • _ENABLE_PER_THREAD_LOCALE
    Verifique a localidade do uso de um determinado segmento thread corrente.As chamadas subseqüentes a setlocale Esse segmento afetam somente a localidade do thread.

  • _DISABLE_PER_THREAD_LOCALE
    Tornar corrente thread usar a localidade global.As chamadas subseqüentes a setlocale neste thread afeta outros segmentos usando a localidade global.

  • zero
    Recupera a configuração corrente para esse segmento específico.

Essas funções afetam o comportamento da setlocale, _tsetlocale, _wsetlocale, _beginthread, e _beginthreadex. Se outro método é usado para criar segmentos, as configurações de localidade não têm nenhum efeito desses segmentos.

Quando por thread localidade é desabilitado, qualquer subseqüente plano de setlocale ou _wsetlocale Altera a localidade de todos os threads. When per-thread locale is enabled, setlocaleor _wsetlocale only affects the current thread's locale.Localidade por thread pode ser habilitada ou desabilitado globalmente para todos os segmentos.Quando por thread local está habilitado globalmente, setlocale ou _wsetlocale em qualquer afetam somente de thread (não apenas o segmento corrente) do thread.

If type não é um dos valores listados na tabela, essa função chama o manipulador de parâmetro inválido, conforme descrito em Validação de parâmetro. Se a execução for permitida para continuar, essa função define errno para EINVAL e retorna -1.

Requisitos

Rotina

Cabeçalho necessário

_configthreadlocale

<localidade.h>

Exemplo

// crt_configthreadlocale.cpp
// 
// This program demonstrates the use of _configthreadlocale when
// using is two independent threads.
//

#include <locale.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];

    // Set the thread local
    printf("The thread local 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];

    // Configure per-thread locale to cause all subsequently created 
    // threads to have their own locale.
    _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);

    // Retrieve the time string from the helper function
    printf("The thread local 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 local is now set to English_United States.1252. The time in English locale is: 'Wednesday, May 12, 2004'  The thread local is now set to German_Germany.1252. The time in German locale is: 'Mittwoch, 12. Mai 2004'

Equivalente do NET Framework

Não aplicável. No entanto, consulte Usando a propriedade CurrentCulture.

Consulte também

Referência

setlocale, _wsetlocale

_beginthread, _beginthreadex

Localidade