Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Move WorkTask callback invocation after task invocation #3722

Closed

Description

@kkaefer

#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.

/cc @jfirebaugh

Activity

  1. changed the title [-]Enforce [/-] [+]Move WorkTask callback invocation after task invocation[/+] on Jan 28, 2016
  2. kkaefer commented on Jan 28, 2016

    @kkaefer
    MemberAuthor

    http://stackoverflow.com/a/4871563/331379 has an interesting bit of code that might be useful for this:

    template <typename Movable>
    auto move_on_invoke(Movable&& m) {
        return std::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.

  3. jfirebaugh commented on Jan 28, 2016

    @jfirebaugh
    Contributor

    👍

    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.
  4. self-assigned this
    on Sep 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions