Skip to content

[Win32] Initialize Windows Runtime on queue threads #595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -6264,8 +6264,13 @@ _dispatch_worker_thread(void *context)
static unsigned WINAPI
_dispatch_worker_thread_thunk(LPVOID lpParameter)
{
_dispatch_worker_thread(lpParameter);
return 0;
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
if (FAILED(hr)) {
_dispatch_client_assert_fail("Error %ld initializing Windows Runtime", hr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we safely assume that CoInitializeEx is enough to initialize the Windows Runtime, when Roinitialize doesn't mention this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was an earlier discussion about these functions here, does that maybe answer your question? Unfortunately I’m not familiar with the differences between the two functions.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CoInitializeEx initialize concurrent model as STA, where RoInitialize by default uses MTA. Though passing RO_INIT_SINGLETHREADED will use STA instead.

}
_dispatch_worker_thread(lpParameter);
CoUninitialize();
return 0;
}
#endif // defined(_WIN32)
#endif // DISPATCH_USE_PTHREAD_POOL
Expand Down