Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : Marcin 'Qrczak' Kowalczyk Date : Fri Feb 04 2005 02:37 am Giancarlo Niccolai writes: >> Because it would change various instances of code written with no >> threads in mind from unsafe to safe to use with threads. > > That is utterly impossible. It is possible. Consider this function: char32_t lookup_unicode_char_by_name(const string &name) { static map database = read_unicode_database_from_file(); map::iterator it = database.find(name); return it == database.end() ? it->second : (char32_t)-1; } If C++ uses non-thread-aware checking for first-time use, it may break in multithreaded environment when several threads try to lookup a name at the same time, even though it may often work by chance. If C++ uses an equivalent of pthread_once, it just works. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ .