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
Copy file name to clipboardExpand all lines: FWCore/Concurrency/README.md
+32-7Lines changed: 32 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,20 +21,45 @@ The easiest way to create an `edm::WaitingTask` is to call `edm::make_waiting_ta
21
21
```
22
22
23
23
### `edm::FinalWaitingTask`
24
-
In the case where one is doing a synchronous wait on a series of asynchronous tasks, it is useful to have a special `edm::WaitingTask` that can sit on the stack and hold onto any `std::exception_ptr` which occur during the asynchronous processing.
24
+
In the case where one is doing a synchronous wait on a series of asynchronous tasks, it is useful to have a special `edm::WaitingTask` that can sit on the stack and hold onto a `std::exception_ptr` if an exception is thrown during the asynchronous processing.
Note that the function `wait` will rethrow any exception stored in `finalTask`. There is an alternative function named `waitNoThrow` which will return the `std::exception_ptr`.
36
+
37
+
WARNING: It important that the finalTask not execute before completion of the construction of all `WaitingTaskHolders` that will be constructed directly from finalTask. The following would be a bug:
This will not wait for the work started in `doMoreWorkAsynchronously` to complete if the work in doLotsOfWorkAsynchronously completes before the second WaitingTaskHolder is constructed. Here is the correct pattern for this case:
50
+
51
+
52
+
```C++
53
+
oneapi::tbb::task_group group;
54
+
edm::FinalWaitingTask finalTask(group);
55
+
{
56
+
edm::WaitingTaskHolder holder(group, &finalTask);
57
+
doLotsOfWorkAsynchronously(holder);
58
+
doMoreWorkAsynchronously(holder);
36
59
}
60
+
finalTask.wait();
37
61
```
62
+
38
63
## `edm::WaitingTaskHolder`
39
64
This class functions as a _smart pointer_ for an `edm::WaitingTask`. On construction it will increment the embedded reference count of the `edm::WaitingTask`. On either the destructor or the call to `doneWaiting(std::exception_ptr)` it will decrement the reference count. If the count goes to 0, the `edm::WaitingTaskHolder` will pass the `std::exception_ptr` onto the `edm::WaitingTask`, call `execute()` under the `tbb:task_group` given to the holder and finally call `recycle()`.
0 commit comments