You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Move WorkTask callback invocation after task invocation #3722
#3711 showed that our work task API is hard to use correctly because after the task invocation, side effects like object destruction can still occur after the caller was notified. This is because the task itself is responsible for notifying the caller. Instead, the task function should return the result, our work task API should then delete the task function (which also deletes any potentially bound objects), before it notifies the caller. This will also guarantee that the task function itself is less likely to perform any actions after it called the callback.
template <typename Movable>
automove_on_invoke(Movable&& m) {
returnstd::bind(static_cast<Movable&& (&)(Movable&)>(std::move<Movable&>),
std::forward<Movable>(m));
}
When you're creating a bind expression that binds a movable-only type, use this function instead of std::move to make sure that the first invocation gets the bound value moved.
The original work task API was like this. We changed it to invokee-calls-callback in fc64e97 for two reasons:
It's difficult to generically handle invocations with a void return type. Prior to fc64e97 we had a special Invoker subclass just for that case. Maybe we can figure out a cleaner solution this time.
With invokee-calls-callback, the invokee can be asynchronous. But this is actually dangerous, because the locking that enforces task lifetime safety assumes it is synchronous.
Activity
[-]Enforce [/-][+]Move WorkTask callback invocation after task invocation[/+]kkaefer commentedon Jan 28, 2016
http://stackoverflow.com/a/4871563/331379 has an interesting bit of code that might be useful for this:
When you're creating a bind expression that binds a movable-only type, use this function instead of
std::moveto make sure that the first invocation gets the bound value moved.jfirebaugh commentedon Jan 28, 2016
👍
The original work task API was like this. We changed it to invokee-calls-callback in fc64e97 for two reasons:
voidreturn type. Prior to fc64e97 we had a specialInvokersubclass just for that case. Maybe we can figure out a cleaner solution this time.