-
Notifications
You must be signed in to change notification settings - Fork 187
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
Make unifex::async_scope::spawn return a unifex::future<> #372
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This diff changes `unifex::async_scope::spawn(Sender auto)` to return a new type, `unifex::lazy<...>`. `lazy<>` is a _Sender_ that completes with the result of the _Sender_ given to `spawn`.
facebook-github-bot
added
the
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
label
Nov 5, 2021
This diff merges the spawned operation's promise with its operation state so there's only one allocation. One consequence of this change is that outstanding operations don't record themselves as complete within their corresponding scope until the associated `lazy<>` is either connected and started, or discarded.
ispeters
changed the title
Make async_scope::spawn return a lazy<>
Make unifex::async_scope::spawn return a unifex::future<>
Nov 7, 2021
In the light of the morning, I think it's wrong to set the event before requesting stop on the stop source because setting the event could lead to destruction of the operation state, invalidating the stop source.
The callers of `request_stop()` are not owners so they may not call `decref()`, which means I can't invoke `set_done()` from `request_stop()`.
Among other clean-up, this diff fixes a stack-use-after-return in `future<>`'s `connect()`.
Squashing and merging so we can start using this internally; I'll re-up this PR as a PR against |
ispeters
added a commit
that referenced
this pull request
Nov 14, 2021
PR #372 has a subtle ownership bug that's mostly attributable to a lack of tests for `detached_spawn` and friends. If `async_scope::cleanup()` triggers `set_done()` on a detached promise because of the stop callback registered on the scope's stope source, we'll delete the operation state while using its `inplace_stop_source`, leading to a use-after-free. This diff fixes the problem by making the guilty stop callback a part-owner in the operation state. There are now three owners: the `future<>` (if there is one), the operation itself, and the stop callback that propagates stop requests from the scope's stop source to each operation's stop source. I'll figure out how to write a unit test that captures the now-fixed failure mode in a future PR.
ispeters
added a commit
that referenced
this pull request
Nov 14, 2021
PR #372 has a subtle ownership bug that's mostly attributable to a lack of tests for `detached_spawn` and friends. If `async_scope::cleanup()` triggers `set_done()` on a detached promise because of the stop callback registered on the scope's stop source, we'll delete the operation state while using its `inplace_stop_source`, leading to a use-after-free. This diff fixes the problem by making the guilty stop callback a part-owner in the operation state. There are now three owners: the `future<>` (if there is one), the operation itself, and the stop callback that propagates stop requests from the scope's stop source to each operation's stop source. I'll figure out how to write a unit test that captures the now-fixed failure mode in a future PR.
janondrusek
pushed a commit
to janondrusek/libunifex
that referenced
this pull request
Apr 25, 2023
…perimental#372) * Make async_scope::spawn return a lazy<> This diff changes `unifex::async_scope::spawn(Sender auto)` to return a new type, `unifex::lazy<...>`. `lazy<>` is a _Sender_ that completes with the result of the _Sender_ given to `spawn`. * Fix memory leak * Rationalize the names of some internal bits * Fuse the promise and the operation state This diff merges the spawned operation's promise with its operation state so there's only one allocation. One consequence of this change is that outstanding operations don't record themselves as complete within their corresponding scope until the associated `lazy<>` is either connected and started, or discarded. * Fix build Looks like our CI turns on exhaustive switch warnings, which I broke. * Fix infinite hang in create_test.cpp * Cleanup * Last bit of cleanup before bed * Try to fix ASAN failure In the light of the morning, I think it's wrong to set the event before requesting stop on the stop source because setting the event could lead to destruction of the operation state, invalidating the stop source. * Fix request_stop() The callers of `request_stop()` are not owners so they may not call `decref()`, which means I can't invoke `set_done()` from `request_stop()`. * Clean up, bug fixes, comments Among other clean-up, this diff fixes a stack-use-after-return in `future<>`'s `connect()`. * Add constraints and run clang-format * Comments, tests, bug fixes, and clang-format * Restore nothrow assertion in detached_spawn_call_on * Round out the async_scope tests add async_scope::attach (facebookexperimental#392) * returned `Sender` needs to be connected and started * avoids paying penalty of `future<>` Fix `record_done` ordering in `async_scope::attach` (facebookexperimental#424) * `record_done`, which decrements outstanding operation count, must be called after `set_*` * add regression test fix cancellation race in async_scope::attach* (facebookexperimental#425) * use refcount to pass ownership of `deliver_result` * replace `fused_stop_source` with `inplace_stop_source` make `async_scope::attached_sender` copyable (facebookexperimental#428) * copy constructor calls `async_scope::try_record_start` internally * copy of attached Sender will increment outstanding number of operations on async_scope `async_scope::attach` cleanup (facebookexperimental#433) * remove unused template argument * add missing test case update `async_scope` docs (facebookexperimental#434) * spawn() -> detached_spawn() * spawn() returns a `future` * add missing public methods add `async_scope::attach` docs (facebookexperimental#434) fix `async_scope_test::attach_record_done` (facebookexperimental#437) fix `tag_invoke(CPO)` in `async_scope` (facebookexperimental#462) add `unifex::v2::async_scope` (facebookexperimental#463) * simpler than `unifex::v1::async_scope` (`nest()` and `join()`) * does not support cancellation Introduce unifex::nest() (facebookexperimental#468) `unifex::nest()` is a CPO that delegates to either a `tag_invoke` customization taking a *Sender* and a "scope" reference, or to a member function on the given scope that takes a *Sender*. This diff wires `unifex::nest()` to the `nest()` member function on `v2::async_scope` and to the `attach()` member function on `v1::async_scope`. Introduce spawn_detached(sender, scope, allocator) (facebookexperimental#470) This diff introduces a new algorithm, `unifex::spawn_detached()`. `spawn_detached` takes a sender, an "async scope", and an optional allocator. It nests the sender in the scope with `unifex::nest`, allocates and operation state using the allocator, and starts that operation. The given async scope may be anything that `nest()` supports, which currently includes both `v1::async_scope` and `v2::async_scope`. Add an internal receiver to v2::async_scope's nest op (facebookexperimental#484) While writing `unifex::spawn_future()`, I discovered that waiting until the destructor of the `v2::async_scope`'s `nest()` operation to drop the scope reference is too late (it led to hangs). This diff adds an internal receiver to the nest operation so we can detect when the operation is complete (which is likely before the operation state is destroyed) and drop the reference as soon as we reach that state. Fix stop_when's handling of stop requests (facebookexperimental#500) * Fix stop_when's handling of stop requests When trying to sync PR facebookexperimental#495 into our internal repo, I discovered that there's a lifetime issue in `stop_when()`. If the `stop_when()` operation receives a stop request from its Receiver and the last-to-finish child operation completes synchronously in response to the stop request then `stop_when()`'s stop callback will access the internal stop source after it's been destroyed. This first diff just formats `test/stop_when_test.cpp` and `include/unifex/stop_when.hpp` with `clang-format` in preparation for fixing the above problem. * Add a broken unit test This diff adds a unit test to `test/stop_when_test.cpp` that crashes when ASAN is enabled because it dereferences a destroyed `inplace_stop_source`. * Increment stop_when's refcount in its stop callback This diff fixes the broken test from the previous diff by incrementing the `stop_when` operation's refcount while processing a stop request from the receiver. Add spawn_future() (facebookexperimental#489) This diff adds `unifex::spawn_future(Sender, Scope)`. Implement async_scope::spawn with spawn_future (facebookexperimental#501) This diff reimplements the `v1::async_scope::spawn()` method in terms of the newly-added `unifex::spawn_future()` algorithm. I had to delete a few tests that exercise behaviour that's no longer supported. Work around an MSVC bug in C++20 mode (facebookexperimental#492) * merge unit test that depends on `v2/async_scope` Co-authored-by: Ian Petersen <ispeters@gmail.com>
janondrusek
pushed a commit
to janondrusek/libunifex
that referenced
this pull request
Apr 25, 2023
…perimental#372) * Make async_scope::spawn return a lazy<> This diff changes `unifex::async_scope::spawn(Sender auto)` to return a new type, `unifex::lazy<...>`. `lazy<>` is a _Sender_ that completes with the result of the _Sender_ given to `spawn`. * Fix memory leak * Rationalize the names of some internal bits * Fuse the promise and the operation state This diff merges the spawned operation's promise with its operation state so there's only one allocation. One consequence of this change is that outstanding operations don't record themselves as complete within their corresponding scope until the associated `lazy<>` is either connected and started, or discarded. * Fix build Looks like our CI turns on exhaustive switch warnings, which I broke. * Fix infinite hang in create_test.cpp * Cleanup * Last bit of cleanup before bed * Try to fix ASAN failure In the light of the morning, I think it's wrong to set the event before requesting stop on the stop source because setting the event could lead to destruction of the operation state, invalidating the stop source. * Fix request_stop() The callers of `request_stop()` are not owners so they may not call `decref()`, which means I can't invoke `set_done()` from `request_stop()`. * Clean up, bug fixes, comments Among other clean-up, this diff fixes a stack-use-after-return in `future<>`'s `connect()`. * Add constraints and run clang-format * Comments, tests, bug fixes, and clang-format * Restore nothrow assertion in detached_spawn_call_on * Round out the async_scope tests add async_scope::attach (facebookexperimental#392) * returned `Sender` needs to be connected and started * avoids paying penalty of `future<>` Fix `record_done` ordering in `async_scope::attach` (facebookexperimental#424) * `record_done`, which decrements outstanding operation count, must be called after `set_*` * add regression test fix cancellation race in async_scope::attach* (facebookexperimental#425) * use refcount to pass ownership of `deliver_result` * replace `fused_stop_source` with `inplace_stop_source` make `async_scope::attached_sender` copyable (facebookexperimental#428) * copy constructor calls `async_scope::try_record_start` internally * copy of attached Sender will increment outstanding number of operations on async_scope `async_scope::attach` cleanup (facebookexperimental#433) * remove unused template argument * add missing test case update `async_scope` docs (facebookexperimental#434) * spawn() -> detached_spawn() * spawn() returns a `future` * add missing public methods add `async_scope::attach` docs (facebookexperimental#434) fix `async_scope_test::attach_record_done` (facebookexperimental#437) fix `tag_invoke(CPO)` in `async_scope` (facebookexperimental#462) add `unifex::v2::async_scope` (facebookexperimental#463) * simpler than `unifex::v1::async_scope` (`nest()` and `join()`) * does not support cancellation Introduce unifex::nest() (facebookexperimental#468) `unifex::nest()` is a CPO that delegates to either a `tag_invoke` customization taking a *Sender* and a "scope" reference, or to a member function on the given scope that takes a *Sender*. This diff wires `unifex::nest()` to the `nest()` member function on `v2::async_scope` and to the `attach()` member function on `v1::async_scope`. Introduce spawn_detached(sender, scope, allocator) (facebookexperimental#470) This diff introduces a new algorithm, `unifex::spawn_detached()`. `spawn_detached` takes a sender, an "async scope", and an optional allocator. It nests the sender in the scope with `unifex::nest`, allocates and operation state using the allocator, and starts that operation. The given async scope may be anything that `nest()` supports, which currently includes both `v1::async_scope` and `v2::async_scope`. Add an internal receiver to v2::async_scope's nest op (facebookexperimental#484) While writing `unifex::spawn_future()`, I discovered that waiting until the destructor of the `v2::async_scope`'s `nest()` operation to drop the scope reference is too late (it led to hangs). This diff adds an internal receiver to the nest operation so we can detect when the operation is complete (which is likely before the operation state is destroyed) and drop the reference as soon as we reach that state. Fix stop_when's handling of stop requests (facebookexperimental#500) * Fix stop_when's handling of stop requests When trying to sync PR facebookexperimental#495 into our internal repo, I discovered that there's a lifetime issue in `stop_when()`. If the `stop_when()` operation receives a stop request from its Receiver and the last-to-finish child operation completes synchronously in response to the stop request then `stop_when()`'s stop callback will access the internal stop source after it's been destroyed. This first diff just formats `test/stop_when_test.cpp` and `include/unifex/stop_when.hpp` with `clang-format` in preparation for fixing the above problem. * Add a broken unit test This diff adds a unit test to `test/stop_when_test.cpp` that crashes when ASAN is enabled because it dereferences a destroyed `inplace_stop_source`. * Increment stop_when's refcount in its stop callback This diff fixes the broken test from the previous diff by incrementing the `stop_when` operation's refcount while processing a stop request from the receiver. Add spawn_future() (facebookexperimental#489) This diff adds `unifex::spawn_future(Sender, Scope)`. Implement async_scope::spawn with spawn_future (facebookexperimental#501) This diff reimplements the `v1::async_scope::spawn()` method in terms of the newly-added `unifex::spawn_future()` algorithm. I had to delete a few tests that exercise behaviour that's no longer supported. Work around an MSVC bug in C++20 mode (facebookexperimental#492) * merge unit test that depends on `v2/async_scope` Co-authored-by: Ian Petersen <ispeters@gmail.com>
janondrusek
pushed a commit
to janondrusek/libunifex
that referenced
this pull request
Apr 26, 2023
…perimental#372) * Make async_scope::spawn return a lazy<> This diff changes `unifex::async_scope::spawn(Sender auto)` to return a new type, `unifex::lazy<...>`. `lazy<>` is a _Sender_ that completes with the result of the _Sender_ given to `spawn`. * Fix memory leak * Rationalize the names of some internal bits * Fuse the promise and the operation state This diff merges the spawned operation's promise with its operation state so there's only one allocation. One consequence of this change is that outstanding operations don't record themselves as complete within their corresponding scope until the associated `lazy<>` is either connected and started, or discarded. * Fix build Looks like our CI turns on exhaustive switch warnings, which I broke. * Fix infinite hang in create_test.cpp * Cleanup * Last bit of cleanup before bed * Try to fix ASAN failure In the light of the morning, I think it's wrong to set the event before requesting stop on the stop source because setting the event could lead to destruction of the operation state, invalidating the stop source. * Fix request_stop() The callers of `request_stop()` are not owners so they may not call `decref()`, which means I can't invoke `set_done()` from `request_stop()`. * Clean up, bug fixes, comments Among other clean-up, this diff fixes a stack-use-after-return in `future<>`'s `connect()`. * Add constraints and run clang-format * Comments, tests, bug fixes, and clang-format * Restore nothrow assertion in detached_spawn_call_on * Round out the async_scope tests add async_scope::attach (facebookexperimental#392) * returned `Sender` needs to be connected and started * avoids paying penalty of `future<>` Fix `record_done` ordering in `async_scope::attach` (facebookexperimental#424) * `record_done`, which decrements outstanding operation count, must be called after `set_*` * add regression test fix cancellation race in async_scope::attach* (facebookexperimental#425) * use refcount to pass ownership of `deliver_result` * replace `fused_stop_source` with `inplace_stop_source` make `async_scope::attached_sender` copyable (facebookexperimental#428) * copy constructor calls `async_scope::try_record_start` internally * copy of attached Sender will increment outstanding number of operations on async_scope `async_scope::attach` cleanup (facebookexperimental#433) * remove unused template argument * add missing test case update `async_scope` docs (facebookexperimental#434) * spawn() -> detached_spawn() * spawn() returns a `future` * add missing public methods add `async_scope::attach` docs (facebookexperimental#434) fix `async_scope_test::attach_record_done` (facebookexperimental#437) fix `tag_invoke(CPO)` in `async_scope` (facebookexperimental#462) add `unifex::v2::async_scope` (facebookexperimental#463) * simpler than `unifex::v1::async_scope` (`nest()` and `join()`) * does not support cancellation Introduce unifex::nest() (facebookexperimental#468) `unifex::nest()` is a CPO that delegates to either a `tag_invoke` customization taking a *Sender* and a "scope" reference, or to a member function on the given scope that takes a *Sender*. This diff wires `unifex::nest()` to the `nest()` member function on `v2::async_scope` and to the `attach()` member function on `v1::async_scope`. Introduce spawn_detached(sender, scope, allocator) (facebookexperimental#470) This diff introduces a new algorithm, `unifex::spawn_detached()`. `spawn_detached` takes a sender, an "async scope", and an optional allocator. It nests the sender in the scope with `unifex::nest`, allocates and operation state using the allocator, and starts that operation. The given async scope may be anything that `nest()` supports, which currently includes both `v1::async_scope` and `v2::async_scope`. Add an internal receiver to v2::async_scope's nest op (facebookexperimental#484) While writing `unifex::spawn_future()`, I discovered that waiting until the destructor of the `v2::async_scope`'s `nest()` operation to drop the scope reference is too late (it led to hangs). This diff adds an internal receiver to the nest operation so we can detect when the operation is complete (which is likely before the operation state is destroyed) and drop the reference as soon as we reach that state. Fix stop_when's handling of stop requests (facebookexperimental#500) * Fix stop_when's handling of stop requests When trying to sync PR facebookexperimental#495 into our internal repo, I discovered that there's a lifetime issue in `stop_when()`. If the `stop_when()` operation receives a stop request from its Receiver and the last-to-finish child operation completes synchronously in response to the stop request then `stop_when()`'s stop callback will access the internal stop source after it's been destroyed. This first diff just formats `test/stop_when_test.cpp` and `include/unifex/stop_when.hpp` with `clang-format` in preparation for fixing the above problem. * Add a broken unit test This diff adds a unit test to `test/stop_when_test.cpp` that crashes when ASAN is enabled because it dereferences a destroyed `inplace_stop_source`. * Increment stop_when's refcount in its stop callback This diff fixes the broken test from the previous diff by incrementing the `stop_when` operation's refcount while processing a stop request from the receiver. Add spawn_future() (facebookexperimental#489) This diff adds `unifex::spawn_future(Sender, Scope)`. Implement async_scope::spawn with spawn_future (facebookexperimental#501) This diff reimplements the `v1::async_scope::spawn()` method in terms of the newly-added `unifex::spawn_future()` algorithm. I had to delete a few tests that exercise behaviour that's no longer supported. Work around an MSVC bug in C++20 mode (facebookexperimental#492) * merge unit test that depends on `v2/async_scope` Co-authored-by: Ian Petersen <ispeters@gmail.com>
janondrusek
pushed a commit
that referenced
this pull request
Apr 27, 2023
* Make async_scope::spawn return a lazy<> This diff changes `unifex::async_scope::spawn(Sender auto)` to return a new type, `unifex::lazy<...>`. `lazy<>` is a _Sender_ that completes with the result of the _Sender_ given to `spawn`. * Fix memory leak * Rationalize the names of some internal bits * Fuse the promise and the operation state This diff merges the spawned operation's promise with its operation state so there's only one allocation. One consequence of this change is that outstanding operations don't record themselves as complete within their corresponding scope until the associated `lazy<>` is either connected and started, or discarded. * Fix build Looks like our CI turns on exhaustive switch warnings, which I broke. * Fix infinite hang in create_test.cpp * Cleanup * Last bit of cleanup before bed * Try to fix ASAN failure In the light of the morning, I think it's wrong to set the event before requesting stop on the stop source because setting the event could lead to destruction of the operation state, invalidating the stop source. * Fix request_stop() The callers of `request_stop()` are not owners so they may not call `decref()`, which means I can't invoke `set_done()` from `request_stop()`. * Clean up, bug fixes, comments Among other clean-up, this diff fixes a stack-use-after-return in `future<>`'s `connect()`. * Add constraints and run clang-format * Comments, tests, bug fixes, and clang-format * Restore nothrow assertion in detached_spawn_call_on * Round out the async_scope tests add async_scope::attach (#392) * returned `Sender` needs to be connected and started * avoids paying penalty of `future<>` Fix `record_done` ordering in `async_scope::attach` (#424) * `record_done`, which decrements outstanding operation count, must be called after `set_*` * add regression test fix cancellation race in async_scope::attach* (#425) * use refcount to pass ownership of `deliver_result` * replace `fused_stop_source` with `inplace_stop_source` make `async_scope::attached_sender` copyable (#428) * copy constructor calls `async_scope::try_record_start` internally * copy of attached Sender will increment outstanding number of operations on async_scope `async_scope::attach` cleanup (#433) * remove unused template argument * add missing test case update `async_scope` docs (#434) * spawn() -> detached_spawn() * spawn() returns a `future` * add missing public methods add `async_scope::attach` docs (#434) fix `async_scope_test::attach_record_done` (#437) fix `tag_invoke(CPO)` in `async_scope` (#462) add `unifex::v2::async_scope` (#463) * simpler than `unifex::v1::async_scope` (`nest()` and `join()`) * does not support cancellation Introduce unifex::nest() (#468) `unifex::nest()` is a CPO that delegates to either a `tag_invoke` customization taking a *Sender* and a "scope" reference, or to a member function on the given scope that takes a *Sender*. This diff wires `unifex::nest()` to the `nest()` member function on `v2::async_scope` and to the `attach()` member function on `v1::async_scope`. Introduce spawn_detached(sender, scope, allocator) (#470) This diff introduces a new algorithm, `unifex::spawn_detached()`. `spawn_detached` takes a sender, an "async scope", and an optional allocator. It nests the sender in the scope with `unifex::nest`, allocates and operation state using the allocator, and starts that operation. The given async scope may be anything that `nest()` supports, which currently includes both `v1::async_scope` and `v2::async_scope`. Add an internal receiver to v2::async_scope's nest op (#484) While writing `unifex::spawn_future()`, I discovered that waiting until the destructor of the `v2::async_scope`'s `nest()` operation to drop the scope reference is too late (it led to hangs). This diff adds an internal receiver to the nest operation so we can detect when the operation is complete (which is likely before the operation state is destroyed) and drop the reference as soon as we reach that state. Fix stop_when's handling of stop requests (#500) * Fix stop_when's handling of stop requests When trying to sync PR #495 into our internal repo, I discovered that there's a lifetime issue in `stop_when()`. If the `stop_when()` operation receives a stop request from its Receiver and the last-to-finish child operation completes synchronously in response to the stop request then `stop_when()`'s stop callback will access the internal stop source after it's been destroyed. This first diff just formats `test/stop_when_test.cpp` and `include/unifex/stop_when.hpp` with `clang-format` in preparation for fixing the above problem. * Add a broken unit test This diff adds a unit test to `test/stop_when_test.cpp` that crashes when ASAN is enabled because it dereferences a destroyed `inplace_stop_source`. * Increment stop_when's refcount in its stop callback This diff fixes the broken test from the previous diff by incrementing the `stop_when` operation's refcount while processing a stop request from the receiver. Add spawn_future() (#489) This diff adds `unifex::spawn_future(Sender, Scope)`. Implement async_scope::spawn with spawn_future (#501) This diff reimplements the `v1::async_scope::spawn()` method in terms of the newly-added `unifex::spawn_future()` algorithm. I had to delete a few tests that exercise behaviour that's no longer supported. Work around an MSVC bug in C++20 mode (#492) * merge unit test that depends on `v2/async_scope` Co-authored-by: Ian Petersen <ispeters@gmail.com>
hawkinsw
pushed a commit
to hawkinsw/libunifex
that referenced
this pull request
May 10, 2023
…perimental#372) * Make async_scope::spawn return a lazy<> This diff changes `unifex::async_scope::spawn(Sender auto)` to return a new type, `unifex::lazy<...>`. `lazy<>` is a _Sender_ that completes with the result of the _Sender_ given to `spawn`. * Fix memory leak * Rationalize the names of some internal bits * Fuse the promise and the operation state This diff merges the spawned operation's promise with its operation state so there's only one allocation. One consequence of this change is that outstanding operations don't record themselves as complete within their corresponding scope until the associated `lazy<>` is either connected and started, or discarded. * Fix build Looks like our CI turns on exhaustive switch warnings, which I broke. * Fix infinite hang in create_test.cpp * Cleanup * Last bit of cleanup before bed * Try to fix ASAN failure In the light of the morning, I think it's wrong to set the event before requesting stop on the stop source because setting the event could lead to destruction of the operation state, invalidating the stop source. * Fix request_stop() The callers of `request_stop()` are not owners so they may not call `decref()`, which means I can't invoke `set_done()` from `request_stop()`. * Clean up, bug fixes, comments Among other clean-up, this diff fixes a stack-use-after-return in `future<>`'s `connect()`. * Add constraints and run clang-format * Comments, tests, bug fixes, and clang-format * Restore nothrow assertion in detached_spawn_call_on * Round out the async_scope tests add async_scope::attach (facebookexperimental#392) * returned `Sender` needs to be connected and started * avoids paying penalty of `future<>` Fix `record_done` ordering in `async_scope::attach` (facebookexperimental#424) * `record_done`, which decrements outstanding operation count, must be called after `set_*` * add regression test fix cancellation race in async_scope::attach* (facebookexperimental#425) * use refcount to pass ownership of `deliver_result` * replace `fused_stop_source` with `inplace_stop_source` make `async_scope::attached_sender` copyable (facebookexperimental#428) * copy constructor calls `async_scope::try_record_start` internally * copy of attached Sender will increment outstanding number of operations on async_scope `async_scope::attach` cleanup (facebookexperimental#433) * remove unused template argument * add missing test case update `async_scope` docs (facebookexperimental#434) * spawn() -> detached_spawn() * spawn() returns a `future` * add missing public methods add `async_scope::attach` docs (facebookexperimental#434) fix `async_scope_test::attach_record_done` (facebookexperimental#437) fix `tag_invoke(CPO)` in `async_scope` (facebookexperimental#462) add `unifex::v2::async_scope` (facebookexperimental#463) * simpler than `unifex::v1::async_scope` (`nest()` and `join()`) * does not support cancellation Introduce unifex::nest() (facebookexperimental#468) `unifex::nest()` is a CPO that delegates to either a `tag_invoke` customization taking a *Sender* and a "scope" reference, or to a member function on the given scope that takes a *Sender*. This diff wires `unifex::nest()` to the `nest()` member function on `v2::async_scope` and to the `attach()` member function on `v1::async_scope`. Introduce spawn_detached(sender, scope, allocator) (facebookexperimental#470) This diff introduces a new algorithm, `unifex::spawn_detached()`. `spawn_detached` takes a sender, an "async scope", and an optional allocator. It nests the sender in the scope with `unifex::nest`, allocates and operation state using the allocator, and starts that operation. The given async scope may be anything that `nest()` supports, which currently includes both `v1::async_scope` and `v2::async_scope`. Add an internal receiver to v2::async_scope's nest op (facebookexperimental#484) While writing `unifex::spawn_future()`, I discovered that waiting until the destructor of the `v2::async_scope`'s `nest()` operation to drop the scope reference is too late (it led to hangs). This diff adds an internal receiver to the nest operation so we can detect when the operation is complete (which is likely before the operation state is destroyed) and drop the reference as soon as we reach that state. Fix stop_when's handling of stop requests (facebookexperimental#500) * Fix stop_when's handling of stop requests When trying to sync PR facebookexperimental#495 into our internal repo, I discovered that there's a lifetime issue in `stop_when()`. If the `stop_when()` operation receives a stop request from its Receiver and the last-to-finish child operation completes synchronously in response to the stop request then `stop_when()`'s stop callback will access the internal stop source after it's been destroyed. This first diff just formats `test/stop_when_test.cpp` and `include/unifex/stop_when.hpp` with `clang-format` in preparation for fixing the above problem. * Add a broken unit test This diff adds a unit test to `test/stop_when_test.cpp` that crashes when ASAN is enabled because it dereferences a destroyed `inplace_stop_source`. * Increment stop_when's refcount in its stop callback This diff fixes the broken test from the previous diff by incrementing the `stop_when` operation's refcount while processing a stop request from the receiver. Add spawn_future() (facebookexperimental#489) This diff adds `unifex::spawn_future(Sender, Scope)`. Implement async_scope::spawn with spawn_future (facebookexperimental#501) This diff reimplements the `v1::async_scope::spawn()` method in terms of the newly-added `unifex::spawn_future()` algorithm. I had to delete a few tests that exercise behaviour that's no longer supported. Work around an MSVC bug in C++20 mode (facebookexperimental#492) * merge unit test that depends on `v2/async_scope` Co-authored-by: Ian Petersen <ispeters@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This diff changes
unifex::async_scope::spawn(Sender auto)
to return anew type,
unifex::future<...>
.future<>
is a Sender that completeswith the result of the Sender given to
spawn
.