Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : Marcin 'Qrczak' Kowalczyk Date : Sun Feb 06 2005 10:42 am Giancarlo Niccolai writes: > I don't want to have thousand of mutexes I can't control around, > especially when I don't need them. Why? Then don't use static locals with dynamic initialization. They are supposed to be initialized on the first time they are used, and in a multithreaded environment the correct implementation of "the first time it is used" needs something like pthread_once - a guard variable is thread-unsafe. > And I can write code that would be broken also by a-mutex-per-class > thing. It's a pthread_once_t per a contiguous block of static locals. It does not break, unless the code is already broken with a guard variable semantics. > And... btw... have you thought about how to... INITIALIZE EACH MUTEX > IN A THREAD-SAFE WAY? As with pthread_once, with PTHREAD_ONCE_INIT. > 1) solves an unexisting problem > 2) can break correct programs > 3) makes an ugly thing (static initialization) just worse. All three claims are false. It just turns the semantics of initialization of static locals from MT-unsafe to MT-safe. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ .