-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add test for main dispatch queue processing in CFRunLoop #2806
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
Conversation
cc @compnerd |
@lxbndr would you mind testing with the test but instead of the Foundation change, swiftlang/swift-corelibs-libdispatch#524? |
I managed to run with the test case, it does pass with the associated PR. I think that we should get the test case added to the test suite still. |
@compnerd You mean swiftlang/swift-corelibs-libdispatch#542, right? One thing feels uncomfortable though. I wanted to place event consumption closer to its processing, because there is, probably, small chance that CFRunLoop will not process Dispatch callout even it sees event raised. Waiting for events is implemented with In this case only the first event would be processed, and others would be lost if they are kind of auto-reset events. |
My understanding is that |
That's right. And this could be a problem. We could be triggered by multiple events, but actually take only one of them for further processing. Would you mind to look into __CFRunLoopWaitForMultipleObjects implementation? Result for our case is set on line 2541. |
Correct, the other events would trigger WFMO to immediately return the next time around in the loop. You have no guarantees on the order in which the events are handled. Im not sure Im understanding the issue. |
Maybe I am just missing something. Here is step by step scenario I see:
Am I correct with my conclusion? |
I see the confusion now. That is not how WFMO functions. It is:
You would also need to handle |
Ah, I see now. Thank you for explanation and perfect solution. Had to re-read the docs thrice. Now I am 100% sure everything will be ok. |
This ensures CFRunLoop correctly serves main dispatch queue. Due to event specifics on Windows there was possibility to break RunLoop making it think that main queue always has pending work. The issue is adressed in swiftlang/swift-corelibs-libdispatch#542.
Removed |
@swift-ci please test |
@swift-ci please test Linux platform |
Thanks for investigating the issue, identifying the problem, and the test case! |
This ensures CFRunLoop correctly serves main dispatch queue.
Due to event specifics on Windows there was possibility to break
RunLoop making it think that main queue always has pending
work. The issue is adressed in swiftlang/swift-corelibs-libdispatch#542.