[Saga-devel] saga SVN commit 3324:
/trunk/saga/saga/adaptors/utils/
'Andre Merzky'
andre at merzky.net
Sun Jan 18 01:12:42 CST 2009
Quoting [Hartmut Kaiser] (Jan 17 2009):
>
> > User: amerzky
> > Date: 2009/01/17 10:37 AM
> >
> > Modified:
> > /trunk/saga/saga/adaptors/utils/
> > utils.cpp
> >
> > Log:
> > don't optimize - C++ static initialization and threads don't go
> > along very well it seems
>
> Thread safe initializations of statics is complex in any language. It's
> definitely not a C++ problem. C suffers from the same subtleties. All global
> data needs to be protected in multithreaded environments. And initialization
> of globals in multi threaded environments is tricky to say the best.
Don't take that personally :-) I am not attacking C++ (this
time), just stating what you told me. If we'd do C, I would
commented about C :-)
Take it easy..., Andre.
> But it is possible, you just have to know how to make it happen. Joao wrote
> a nice helper class based on Boosts init_once facility for doing exactly
> this
> (saga/external/boost/spirit/boost/spirit/core/non_terminal/impl/static.hpp).
>
> Regards Hartmut
>
> BTW: you don't need the 'bool have_localhosts' anymore. As every invocation
> of this functions get's its own copy of the vector anyways.
>
>
> > A
> >
> > File Changes:
> >
> > Directory: /trunk/saga/saga/adaptors/utils/
> > ===========================================
> >
> > File [modified]: utils.cpp
> > Delta lines: +2 -6
> > ===================================================================
> > --- trunk/saga/saga/adaptors/utils/utils.cpp 2009-01-17 16:08:08 UTC
> > (rev 3323)
> > +++ trunk/saga/saga/adaptors/utils/utils.cpp 2009-01-17 16:37:19 UTC
> > (rev 3324)
> > @@ -177,14 +177,10 @@
> > // a '.' in its name.
> > std::vector <std::string> get_localhosts (void)
> > {
> > - // scoped lock, to protect the static variables
> > - boost::recursive_mutex mtx_;
> > - boost::recursive_mutex::scoped_lock lock (mtx_);
> > -
> > // optimization: build this list only once - we assume that
> > host names
> > // do not change during the runtime of the SAGA application.
> > - static std::vector <std::string> localhosts;
> > - static bool have_localhosts = false;
> > + std::vector <std::string> localhosts;
> > + bool have_localhosts = false;
> >
> >
> > std::set <std::string> initial_names;
> >
> > _______________________________________________
> > saga-devel mailing list
> > saga-devel at cct.lsu.edu
> > https://mail.cct.lsu.edu/mailman/listinfo/saga-devel
>
--
Nothing is ever easy.
More information about the saga-devel
mailing list