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
The following program shows memory errors with valgrind:
use Futures;
use Time;
configconst doGet =false;
proc test() {
var F = async(lambda(x:int) { sleep(1); return42+ x; }, 23);
if doGet then
F.get();
}
proc main() {
test();
}
These errors go away if the --doGet=true argument is passed.
Why is this happening? The async call creates a future and returns it. The future destructor doesn't wait for the task and cleans up the memory. Then, the task finishes and tries to store the result in the future's state.
Fix two problems in the Futures package module
This PR fixes two memory errors in the Futures package module.
Resolves#15117.
The first is described in issue #15117. This PR fixes that case by
waiting for the future to complete if it was not completed when the
future is trying to delete the class managing it. A reasonable
alternative would be to increment the reference count to that class in
the task running the future.
The second issue is a problem that surfaces due to PR #15041 that
appeared as a test failure for futures-doc-validity.chpl. The problem is
with constructions like this:
``` chapel
// from assign-then-get.chpl
var G: Future(int);
assert(G.isValid() == false);
G = async(lambda(x: int) { return 10 + x; }, 1); // HERE
const g = G.get();
```
The problem is that the first-class-function is deinited at the end of
the statement in which it was declared, at the `HERE` comment above. To
fix that, made the futures functions accept task function arguments with
the `in` intent and pass them to the begin also with `in` intent.
Reviewed by @vasslitvinov - thanks!
- [x] test/library/packages/Futures passes with valgrind
- [x] full local testing
The following program shows memory errors with valgrind:
These errors go away if the
--doGet=true
argument is passed.Why is this happening? The
async
call creates a future and returns it. The future destructor doesn't wait for the task and cleans up the memory. Then, the task finishes and tries to store the result in the future's state.Associated Future Test:
test/library/packages/Futures/bug-15117.chpl (PR #15118)
The text was updated successfully, but these errors were encountered: