Explain the need for mutexes in locales, please

Reading the question Why does C ++ STL not support atoi (const string &) as functions? I came across a comment that warned that GCC (at least) has a bug , which could slow down multithreaded applications that often use ostringstream. This is apparently due to the mutex, "necessary" for the language mechanism in C ++.

Given my recent interest in the practice of globalization, I wonder if anyone can explain to me why a locale object needs a mutex? What can this be changed in a locale that needs a mutex? Can't it be read-only?

+3
source share
2 answers

This is really an implementation problem, but std::localehas a static function that retrieves and sets the global locale. The global locale is defined for use in several areas of the standard library, which implies that somewhere there must be global localization.

In implementations that support threads, it is very likely that this global locale should be protected with some sort of locking mechanism to prevent simultaneous access between threads due to unwanted behavior.

, , ( ) .

+3

- , , . , :

.

iostream, , . , , 1987, , , .

+1

Source: https://habr.com/ru/post/1723475/


All Articles