Aracılığıyla paylaş


_configthreadlocale

İş parçacığı başına yerel ayar seçeneklerini yapılandırıyor.

Sözdizimi

int _configthreadlocale( int per_thread_locale_type );

Parametreler

per_thread_locale_type
Ayar seçeneği. Aşağıdaki tabloda listelenen seçeneklerden biri.

Dönüş değeri

Hata durumunda önceki iş parçacığı başına yerel ayar durumu (_DISABLE_PER_THREAD_LOCALE veya _ENABLE_PER_THREAD_LOCALE) veya -1.

Açıklamalar

_configthreadlocale İşlev, iş parçacığına özgü yerel ayarların kullanımını denetlemek için kullanılır. İş parçacığı başına yerel ayar durumunu belirtmek veya belirlemek için şu per_thread_locale_type seçeneklerden birini kullanın:

Seçenek Tanım
_ENABLE_PER_THREAD_LOCALE Geçerli iş parçacığının iş parçacığına özgü bir yerel ayar kullanmasını sağlayın. Bu iş parçacığında sonraki setlocale çağrılar yalnızca iş parçacığının kendi yerel ayarını etkiler.
_DISABLE_PER_THREAD_LOCALE Geçerli iş parçacığının genel yerel ayarı kullanmasını sağlayın. Bu iş parçacığındaki sonraki setlocale çağrılar, genel yerel ayarı kullanan diğer iş parçacıklarını etkiler.
0 Bu iş parçacığı için geçerli ayarı alır.

Bu işlevler , , _tsetlocale_wsetlocaleve _setmbcpdavranışlarını setlocaleetkiler. İş parçacığı başına yerel ayar devre dışı bırakıldığında, sonraki çağrılar setlocale veya _wsetlocale genel yerel ayarı kullanan tüm iş parçacıklarının yerel ayarını değiştirir. İş parçacığı başına yerel ayar etkinleştirildiğinde setlocale veya _wsetlocale yalnızca geçerli iş parçacığının yerel ayarını etkilediğinde.

İş parçacığı başına yerel ayarı etkinleştirmek için kullanıyorsanız_configthreadlocale, bu iş parçacığında tercih edilen yerel ayarı hemen ardından veya _wsetlocaleçağrısıyla setlocale ayarlayın.

Tabloda listelenen değerlerden biri değilseper_thread_locale_type, bu işlev Parametre doğrulama bölümünde açıklandığı gibi geçersiz parametre işleyicisini çağırır. Yürütmenin devam etmesi için izin verilirse, bu işlev olarak EINVAL ayarlanır errno ve -1 döndürür.

Varsayılan olarak, bu işlevin genel durumunun kapsamı uygulama olarak belirlenmiştir. Bu davranışı değiştirmek için bkz. CRT'de Genel durum.

Gereksinimler

Yordam Gerekli başlık
_configthreadlocale '<locale.h>'

Örnek

// 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'

Ayrıca bkz.

setlocale, _wsetlocale
_beginthread, _beginthreadex
Yerel ayar
Çoklu iş parçacığı kullanımı ve yerel ayarlar