Same, but with also a failing task
| 256 | |
| 257 | // Same, but with also a failing task |
| 258 | void StressFailingTaskGroupLifetime(std::function<std::shared_ptr<TaskGroup>()> factory) { |
| 259 | const int NTASKS = 100; |
| 260 | auto task_group = factory(); |
| 261 | auto weak_group_ptr = std::weak_ptr<TaskGroup>(task_group); |
| 262 | |
| 263 | std::atomic<bool> barrier(false); |
| 264 | |
| 265 | BarrierTask task{&barrier, weak_group_ptr, Status::OK()}; |
| 266 | BarrierTask failing_task{&barrier, weak_group_ptr, Status::Invalid("XXX")}; |
| 267 | |
| 268 | for (int i = 0; i < NTASKS; ++i) { |
| 269 | task_group->Append(task); |
| 270 | } |
| 271 | task_group->Append(failing_task); |
| 272 | |
| 273 | // Lose strong reference |
| 274 | barrier.store(true); |
| 275 | task_group.reset(); |
| 276 | |
| 277 | // Wait for finish |
| 278 | while (!weak_group_ptr.expired()) { |
| 279 | SleepFor(1e-5); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | void TestNoCopyTask(std::shared_ptr<TaskGroup> task_group) { |
| 284 | auto counter = std::make_shared<uint8_t>(0); |