Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5300a67

Browse files
author
Jonathan Peyton
authored
[OpenMP] Fix re-locking hang found in issue 86684 (#88539)
This was initially reported here (including stacktraces): https://stackoverflow.com/questions/78183545/does-compiling-imagick-with-openmp-enabled-in-freebsd-13-2-cause-sched-yield If `__kmp_register_library_startup()` detects that another instance of the library is present, `__kmp_is_address_mapped()` is eventually called. which uses `kmpc_alloc()` to allocate memory. This function calls `__kmp_entry_thread()` to access the thread-local memory pool, which is a bad idea during initialization. This macro internally calls `__kmp_get_global_thread_id_reg()` which sets the bootstrap lock at the beginning (before calling `__kmp_register_library_startup()`). The fix is to use `KMP_INTERNAL_MALLOC()`/`KMP_INTERNAL_FREE()` instead of `kmpc_malloc()`/`kmpc_free()`. `KMP_INTERNAL_MALLOC` and `KMP_INTERNAL_FREE` do not use any bootstrap locks. They just translate to `malloc()`/`free()` and are meant to be used during library initialization before other library-specific allocators have been initialized. Fixes: #86684
1 parent 41ff91e commit 5300a67

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

openmp/runtime/src/z_Linux_util.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,10 +2141,10 @@ int __kmp_is_address_mapped(void *addr) {
21412141
// We pass from number of vm entry's semantic
21422142
// to size of whole entry map list.
21432143
lstsz = lstsz * 4 / 3;
2144-
buf = reinterpret_cast<char *>(kmpc_malloc(lstsz));
2144+
buf = reinterpret_cast<char *>(KMP_INTERNAL_MALLOC(lstsz));
21452145
rc = sysctl(mib, 4, buf, &lstsz, NULL, 0);
21462146
if (rc < 0) {
2147-
kmpc_free(buf);
2147+
KMP_INTERNAL_FREE(buf);
21482148
return 0;
21492149
}
21502150

@@ -2168,7 +2168,7 @@ int __kmp_is_address_mapped(void *addr) {
21682168
}
21692169
lw += cursz;
21702170
}
2171-
kmpc_free(buf);
2171+
KMP_INTERNAL_FREE(buf);
21722172
#elif KMP_OS_DRAGONFLY
21732173
char err[_POSIX2_LINE_MAX];
21742174
kinfo_proc *proc;
@@ -2234,12 +2234,12 @@ int __kmp_is_address_mapped(void *addr) {
22342234
return 0;
22352235
}
22362236

2237-
buf = kmpc_malloc(sz);
2237+
buf = KMP_INTERNAL_MALLOC(sz);
22382238

22392239
while (sz > 0 && (rd = pread(file, buf, sz, 0)) == sz) {
22402240
void *newbuf;
22412241
sz <<= 1;
2242-
newbuf = kmpc_realloc(buf, sz);
2242+
newbuf = KMP_INTERNAL_REALLOC(buf, sz);
22432243
buf = newbuf;
22442244
}
22452245

@@ -2255,7 +2255,7 @@ int __kmp_is_address_mapped(void *addr) {
22552255
}
22562256
}
22572257

2258-
kmpc_free(map);
2258+
KMP_INTERNAL_FREE(map);
22592259
close(file);
22602260
KMP_INTERNAL_FREE(name);
22612261
#elif KMP_OS_DARWIN

0 commit comments

Comments
 (0)