[Chapel Merge] Adjust chpl-cache initialization logic

Branch: refs/heads/main
Revision: 9ff3cb1
Author: mppf
Link: Adjust chpl-cache initialization logic by mppf · Pull Request #18800 · chapel-lang/chapel · GitHub
Log Message:

Merge pull request #18800 from mppf/cache-remote-init-logic

Adjust chpl-cache initialization logic

For https://github.com/Cray/chapel-private/issues/2768

This PR adjusts chpl-cache.c to not allow the cache to be used until
after chpl_cache_init is run. That prevents the cache from causing
surprising behavior during runtime and program initialization.

To do so, it makes tls_cache_remote_data potentially return NULL if the
cache was not yet inited. It was already the case that it could return
NULL if the cache was not enabled at compile time.

Because we don't have C static initializers for atomics in the C runtime
(issue #18801), this code uses a pthread mutex around the new global
is_inited for the cache. When doing a cache operation, each thread will
get the thread-local cache information and in that case it doesn't need
to check the mutex at all. If the thread-local cache information is NULL
then it needs to do allocation and setup and that is where the additional
mutex is now present.

  • [x] test/runtime/configMatters/comm/cache-remote/ passes with local UDP
  • [x] full gasnet testing

Reviewed by @ronawho - thanks!

Modified Files:
M runtime/src/chpl-cache.c

Compare: https://github.com/chapel-lang/chapel/compare/300650f56488...9ff3cb18323b