Skip to content

Conversation

@kennykerr
Copy link
Collaborator

@kennykerr kennykerr commented Oct 10, 2019

The OS uses a form of activity tracking to log events that might complete asynchronously. When this is mixed with coroutines, the activity is tripped up because it does not realize that a suspension point may have switched the thread on which it is executing. This update provides a very low-level hook for use by WIL to notify the system that a coroutine is being suspended or resumed. As with the winrt_to_hresult_handler hook, this is intended for low-level interop with WIL and I don't recommend developers using this as a general purpose notification mechanism.

The "get_awaiter" implementation here is pretty convoluted, but fortunately C++23 will have more library support for coroutines including a "get_awaiter" like function that will be part of the standard library.

@oldnewthing
Copy link
Member

Don't we need to add an await_transform to fire_and_forget too?

@kennykerr
Copy link
Collaborator Author

@oldnewthing right, I'll add that.

}

template <typename T>
struct notify_awaiter
Copy link
Member

Choose a reason for hiding this comment

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

Consider moving this out of impl so it can be used by user-defined promise types. (Like my simple_task<T>.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a pretty invasive hook so I'll give it some time to bake, make sure it's what we really want, and then make a helper available outside the impl namespace.

@kennykerr kennykerr changed the title Adding low-level coroutine suspension notifications Add low-level coroutine suspension notifications Oct 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants