Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2006 Jun : Indy

www.cryer.info
Managed Newsgroup Archive

Indy

Subject:Indy
Posted by:"Ricardo Carmo" (nwlm..@yahoo.com.br)
Date:Fri, 16 Jun 2006 10:16:23

Hi all.
My question is about thread safety.

Clients is a TThreadList, and it contains all the "client threads" alive for
a Server Socket.
May I to read data from the socket with a "ServerExecute" procedure, and
write data to the socket with a "WriteData" procedure, like the procs below?
Is it thread safe?

type
  PClient = ^TClient;
  TClient = record
    Thread: Pointer;
  end;

procedure TTEDREPLIC.ServerExecute(AThread: TIdPeerThread);
begin
  While (not AThread.Terminated) and (AThread.Connection.Connected) do begin
    try
      AThread.Connection.ReadLn();
    except
    end;
  end;
end;

procedure TTEDREPLIC.WriteData;
var RecThread: TIdPeerThread;
      RecClient: PClient;
      r: Integer;
      Command: string;
begin
  with Clients.LockList do begin
    try
        Command:='test';
        for r:=0 to Count-1 do begin
          RecClient:=Items[r];
          RecThread:=RecClient.Thread;
          if (not RecThread.Terminated) and (RecThread.Connection.Connected)
then begin
            try
              RecThread.Connection.WriteLn(Command);
            except
            end;
          end;
        end;
    finally
      Clients.UnlockList;
    end;
end;

Replies:

www.cryer.info
Managed Newsgroup Archive