Jump to content
Registration disabled at the moment Read more... ×
Guest

[Q] OmniThreadLibry AV at Task.Invoke

Recommended Posts

Guest

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 by Guest

Share this post


Link to post
Guest

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 by Guest

Share this post


Link to post
Guest

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 by Guest

Share this post


Link to post

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×