Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : Bruce Visscher Date : Fri Feb 11 2005 02:02 pm > It *might*. But don't you want to write code that guaranteed to > work because it complies with the relevant standards Absolutely. > rather than code that just > happens to work because you fixed all the problems that were biting > you but left the ones that didn't happen to bite you that day, on > that compiler, on that platfor, with that data set? No, I want to avoid that. > I think the '__thread' keyword was meant to mark a thread-local > variable. If you don't have it, you need to use whatever thread-local > variable support you do have. I'll have to ponder how to do this using the pthread interface. > Sounds like you're trying to code to a particular platform. Actually, I am trying to avoid that. > You'll need > to find someone with specialized knowledge about that platform, I think I might be able to write: #ifdef __VMS Item &cofu() { static Item the_item; return the_item; } #elif HAVE_THREAD_KEYWORD // use the __thread keyword as suggested in this (ng) thread. #else // I want to know what goes here. #endif Before "resorting" to pthread_key_create / pthread_getspecific / pthread_setspecific / pthread_key_delete I could also maybe try to use atomic exchange for those platforms that have that. But this is starting to look a little cumbersome. > and your code will not be portable. That's what I am trying to avoid. Thank you for your patience. .