JeffersonLab / chroma

The Chroma Software System for Lattice QCD
http://jeffersonlab.github.io/chroma
Other
58 stars 50 forks source link

Undefined behavior if static multiXd LatticeObjects are used #21

Closed bglaessle closed 7 years ago

bglaessle commented 7 years ago

Static variables like the phases in lib/util/gauge/stag_phases_s.cc and

static multiXd<LatticeABC> abc;

cause undefined behavior if they have size>0 when the program exits.

This is due to the fact that the order of initialization (and therefore deconstruction) of the qdp++ allocator map (the_alignment_map) and the empty multiXd is undefined. Maybe worse is that the qdp allocator hooks atexit, whereas the multiXd, which requires the allocator, is definitely destroyed after that.

A hacky patch for the staggered phases issue is bglaessle@e2a13137b2afdce7667514049064478c8a88609d, but one could also replace the static variables by objects in the NamedObjMap. I can create a merge request if your interested.

Generally one should either prevent these kinds of variables or maybe make the_alignment_map a member of the allocator. Therefore I can open an issue in qdp++.

Furthermore I have not checked chroma or other code bases for more of these static variables.

bglaessle commented 7 years ago

moved this to https://github.com/usqcd-software/qdpxx/issues/23