Skip to content

Commit f38b777

Browse files
committed
Use GetThreadId instead of Storing Handles Directly
CoreFoundation keeps a Dictionary of threads to their runloops. On Windows, it previously used the threads' Handle as keys into the dictionary. However, this doesn't work, as if you are attempting to look up or set the current thread's RunLoop using GetCurrentThread. GetCurrentThread returns a psuedo handle (FFFFFFFE) rather than a real handle to a thread which causes it to index incorrectly into the dictionary. This was causing the creation of multiple runloops per thread and then causing dispatch queues not to be pumped leaving blocks to never be run. The fix here is to use the thread id instead of a handle which is unique on the system until the thread terminates.
1 parent 6a1ca96 commit f38b777

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

CoreFoundation/RunLoop.subproj/CFRunLoop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static void _runLoopTimerWithBlockContext(CFRunLoopTimerRef timer, void *opaqueB
153153
#if TARGET_OS_WIN32
154154

155155
static _CFThreadRef const kNilPthreadT = INVALID_HANDLE_VALUE;
156-
#define pthreadPointer(a) a
156+
#define pthreadPointer(a) (GetThreadId(a))
157157
typedef int kern_return_t;
158158
#define KERN_SUCCESS 0
159159

0 commit comments

Comments
 (0)