DPStano 15 Posted September 13, 2020 (edited) I'm getting multiple reports of AccessViolations inside Task.Invoke function call, it seems that Task.Invoke can/will be called after thread termination unlike TThread.Queue that will not. is that correct behavior, how to wait for the end of Task.Invoke execution? @Primož Gabrijelčič Edited September 13, 2020 by DPStano Share this post Link to post
Primož Gabrijelčič 223 Posted September 16, 2020 Please provide a minimal program that demonstrates the problem. Share this post Link to post
DPStano 15 Posted September 16, 2020 (edited) I can't reproduce it myself, just see it in logs from testers my code looks like sample below https://gist.github.com/Sorien/d62c81f853f831f309c3d71bbc80209d (stripped sample) AV/Null pointer exception happens at the first line of invoke method https://gist.github.com/Sorien/d62c81f853f831f309c3d71bbc80209d#file-unit12-pas-L59 Edited September 16, 2020 by DPStano Share this post Link to post
DPStano 15 Posted September 18, 2020 (edited) same AV i see in logs from OnTerminated FTask := CreateTask( procedure(const Task: IOmniTask) begin end).Unobserved.OnTerminated(OnThreadTermination).Join(FTaskGroup) ... procedure TFoo.OnThreadTermination(const Task: IOmniTaskControl); begin FTaskGroup.Remove(FTask); //AV Here ... but TFoo holding FTask And FTaskGroup reference is waiting for WaitForAll in its destructor destructor TFoo.Destroy; begin // stop all threads FCancellationToken.Signal; FTaskGroup.WaitForAll; it looks like OnTerminated will be somehow called after WaitForAll Edited September 18, 2020 by DPStano Share this post Link to post