Skip to content

Commit 468aabb

Browse files
committed
base: initialize the main thread handle properly
On Windows, there is no `pthread_self`. Duplicate and leak the handle for the main thread. Since this is a global singleton, the overhead should be fine.
1 parent 41b7011 commit 468aabb

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

CoreFoundation/Base.subproj/CFRuntime.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,9 +1117,14 @@ void __CFInitialize(void) {
11171117

11181118
#if DEPLOYMENT_TARGET_WINDOWS
11191119
if (!pthread_main_np()) HALT; // CoreFoundation must be initialized on the main thread
1120-
#endif
1120+
1121+
DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
1122+
GetCurrentProcess(), &_CFMainPThread, 0, FALSE,
1123+
DUPLICATE_SAME_ACCESS);
1124+
#else
11211125
// move this next line up into the #if above after Foundation gets off this symbol. Also: <rdar://problem/39622745> Stop using _CFMainPThread
11221126
_CFMainPThread = pthread_self();
1127+
#endif
11231128

11241129
#if DEPLOYMENT_TARGET_WINDOWS
11251130
// Must not call any CF functions

0 commit comments

Comments
 (0)