Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Apr : TObjectList MultiThread Use?

www.cryer.info
Managed Newsgroup Archive

TObjectList MultiThread Use?

Subject:TObjectList MultiThread Use?
Posted by:"FeliXus" (bilcan [at] gmail.com)
Date:Wed, 18 Apr 2007 12:32:45

---------------------------------------------------------------
Hi I am using TObjectlist in a multithread application like this
---------------------------------------------------------------

Procedure TAddThread.Execute;
Begin
    ...............
    ..............
    ..............
    AnyObject := Tobject.Create;
        Try
          GCCS.Enter;
           Try
              GCList.Add(AnyObject);
           Except;
           End;
        Finally;
          GCCS.Leave;
        End;
End;


Procedure TRunThread.Execute;
Begin
   While Not Terminated do
   Begin
       If GCList.Count>0 then
       Begin
          Try
             DoSomething;
           ......
           ......
          Except;
          End;

        Try
          GCCS.Enter;
           Try
              GCList.Delete(0);
           Except;
           End;
        Finally;
          GCCS.Leave;
        End;
    End;

   Sleep(1);
  end;

End;

......
.....
initialization

Begin
  GCList       := TObjectList.Create;
  GCCS       := TCriticalSection.Create;
End;
end.


---------------------------------------------------------------
If I use TObjectlist in a multithread application (5 Thread adding data to
TObjectlist , and 5 thread delete data from TObjectList) am I encounter any
problem. I am use TCriticalsection only for Adding and deleting from
TObjectlist queue, is this true?
Sory for bad english.
---------------------------------------------------------------

Replies:

www.cryer.info
Managed Newsgroup Archive