Skip to content

Commit 281d78a

Browse files
committed
Only call pthread_key_create once in __CFTSDInitialize
We were calling pthread_key_create more than PTHREAD_KEYS_MAX times (1024 on the version of Linux I tested with). It should only need to be called once. Fixes https://bugs.swift.org/browse/SR-9241
1 parent 007f527 commit 281d78a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

CoreFoundation/Base.subproj/CFPlatform.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,10 @@ CF_PRIVATE void __CFFinalizeWindowsThreadData() {
612612
static pthread_key_t __CFTSDIndexKey;
613613

614614
CF_PRIVATE void __CFTSDInitialize() {
615-
(void)pthread_key_create(&__CFTSDIndexKey, __CFTSDFinalize);
615+
static dispatch_once_t once;
616+
dispatch_once(&once, ^{
617+
(void)pthread_key_create(&__CFTSDIndexKey, __CFTSDFinalize);
618+
});
616619
}
617620

618621
static void __CFTSDSetSpecific(void *arg) {

0 commit comments

Comments
 (0)