Jump to content
PatV

OmniThreadPool race conditions

Recommended Posts

Hi all,

 

Is it possible I have a race condition in a thread pool ?

 

when I launch a task, I get a database connection from my database factory, but when the worker want to use it, Sometimes I've got an error message "mysql server has gone away", if I'm retrying after few sec, I didn't get the error message again, everything is working.  Is there a specific status that a Thread from the thread pool is going to be destroyed ?

 

Thanks

 

Patrick

 

FPoolSearch is definined as iOmniThreadPool;

 

procedure TFrameCustomer.SearchForId(aValue : integer);
var
 Params : TParameters;
const
  cParam = 'I_IDCLI';
begin

 WithParamsReset(Params);
 WithParam(Params,cParam, aValue ,dtInteger);

 

 CreateTask(WorkerSearchId, GetTGUIDString )
      .OnMessage(TaskMessage)
      .OnTerminated(TaskTerminated)
      .SetParameter('Params',TOmniValue.FromArray<rParameter>(Params))
      .SetParameter('ProcName','prc_ClientSearchId')
      .Schedule(FPoolSearch);
end;

 

{------------------------------------------------------------------------}

 

procedure WorkerSearchId(const task: IOmniTask);

   function FillData : TFCustomer;
   var
     aCust : TFCustomer;
    begin
     result:=TFCustomer.Create;
     with (task.ThreadData as  TConnectionPoolData) do
     begin
       with DM.Proc do   // Datamodule . Procedure
       begin
           WorkOnParams;   // Inject parameters from the procedure
           Open;
           if RecordCount>0 then  FilInfo(result,task);
       end;
     end;
    end;
var
 aOVValue : TOmniValue;
 aRes : TFCustomer;
begin
 (task.ThreadData as IConnectionPoolData)
                     .WithProcedureName(task.Param['ProcName'])
                     .WithParameters(task.Param['Params']);

  aRes := FillData;
  aOVValue := TOmniValue.CastFrom<TFCustomer>(TFCustomer.Clone(aRes));
  aRes.Free;

  task.Comm.Send(MSG_SHOW,aOVValue);
end;

 

 


 

 

 

 

 

 

 

 

 

 

 

 

Share this post


Link to post
16 minutes ago, PatV said:

Is it possible I have a race condition

Yes. The answer does not depend on the rest of the statement 😞

 

Thread pool does not get destroyed unless you destroy it in the code. 

 

A thread from a thread pool does not get destroyed while it is running your code.

 

You can process thread pool events to be informed when a thread will be destroyed: http://www.omnithreadlibrary.com/book/chap07.html#lowlevel-threadpool-monitoring

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×