-
Notifications
You must be signed in to change notification settings - Fork 1
Determine if context can actually be movable #90
Description
There are a number of potential bugs that can occur when an async::context is moved. If the following problems below cannot be fixed, then context will have to become immovable once again.
1. Stack pointer invalidation
Currently the stack pointer object is located within the context object. When a coroutine's frame is allocated on the context's stack, the first word is set to the address of the stack pointer. The problem with this, is that the address becomes invalid the moment you move the context and the stack pointer's address is no longer where it was before. I
n order to prevent this invalidation, we need to put the stack pointer somewhere where it is always accessible by the context stack. My initial suggestion is to make the 1st word in the stack the stack pointer. We must also add documentation that makes it very clear that the memory provided to a stack must not be moved/relocated if its not empty. When one coroutine calls the next, it may have passed a reference or address to the called coroutines and those address need to not change underneath those coroutines.
Proxies will simply start their own stack with their stack pointer at the top of the stack. Same as before but stored on the stack.
Note
This will reduce the context size by one word, ensuring that its within a 8-word cache line
2. Proxies
Proxies currently cannot be moved so thats not a problem. But if the original is moved, then the m_original pointer will be invalidated. This might be the killer that makes context no longer movable.