[Chapel Merge] Fix a race in memory tracking initialization

Branch: refs/heads/main
Revision: 961d038
Author: ronawho
Log Message:

Merge pull request #18312 from ronawho/fix-memTracking-init-race

Fix a race in memory tracking initialization

[reviewed by @gbtitus]

Previously, we set chpl_memTrack before we initialized our memory
tracking table. We believed this wasn't an issue because we initialize
the memory tracking in between 2 barrier calls so we assumed nothing
else could be running concurrently. However, prior to #18309 the module
code that's used to initialize memory tracking had on-stmts and so we
did have other threads on locale 0 concurrently running and allocating
memory. That PR happened to work around the issue, but here we solve it
in a more principled manner by only setting chpl_memTrack after we
allocate the table and issue a memory fence.

Resolves Cray/chapel-private#1656

Modified Files:
M runtime/src/chplmemtrack.c

Compare: https://github.com/chapel-lang/chapel/compare/644d609c0a04...961d038c020f