|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
| 16 | +#include <unifex/async_manual_reset_event.hpp> |
16 | 17 | #include <unifex/inplace_stop_token.hpp> |
17 | 18 | #include <unifex/just_from.hpp> |
18 | 19 | #include <unifex/nest.hpp> |
19 | 20 | #include <unifex/scheduler_concepts.hpp> |
| 21 | +#include <unifex/single_thread_context.hpp> |
20 | 22 | #include <unifex/spawn_detached.hpp> |
21 | 23 | #include <unifex/sync_wait.hpp> |
22 | 24 | #include <unifex/v1/async_scope.hpp> |
@@ -53,6 +55,41 @@ TEST(Debug, DISABLED_SyncWaitDeadlockV1Meth) { |
53 | 55 | })); |
54 | 56 | } |
55 | 57 |
|
| 58 | +TEST(Debug, DISABLED_SyncWaitDeadlockV1TooLate) { |
| 59 | + single_thread_context ctx; |
| 60 | + v1::debug_async_scope scope; |
| 61 | + async_manual_reset_event evt; |
| 62 | + std::atomic_bool scheduled{false}; |
| 63 | + |
| 64 | + // wait for evt to be set on a background thread; note that the `async_wait()` |
| 65 | + // _Sender_ is unstoppable |
| 66 | + auto fut = scope.spawn_on( |
| 67 | + ctx.get_scheduler(), |
| 68 | + sequence( |
| 69 | + just_from([&scheduled]() noexcept { scheduled = true; }), |
| 70 | + evt.async_wait())); |
| 71 | + |
| 72 | + // wait for the scheduled op to be started |
| 73 | + while (!scheduled) { |
| 74 | + continue; |
| 75 | + } |
| 76 | + // send a stop request to all the Senders spawned within the scope; this will |
| 77 | + // trigger the future to cancel itself, but not the unstoppable `async_wait()` |
| 78 | + scope.request_stop(); |
| 79 | + |
| 80 | + // with the scope joined, pending futures should all immediately |
| 81 | + // complete with done. result has no value. |
| 82 | + auto result = sync_wait(std::move(fut)); |
| 83 | + ASSERT_FALSE(result.has_value()); |
| 84 | + |
| 85 | + // but the scope itself won't complete until the spawned work is actually |
| 86 | + // done so we will be stuck waiting for the event to be signaled |
| 87 | + sync_wait(scope.cleanup()); |
| 88 | + |
| 89 | + // it's too late. this should be called before `scope.cleanup()` |
| 90 | + evt.set(); |
| 91 | +} |
| 92 | + |
56 | 93 | TEST(Debug, DISABLED_SyncWaitDeadlockV2) { |
57 | 94 | v2::debug_async_scope scope; |
58 | 95 | spawn_detached( |
|
0 commit comments