JackTrapper / dwscript

Automatically exported from code.google.com/p/dwscript
0 stars 0 forks source link

TIOCPWorkerThreadPool #480

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This example will have one thread left over. And for some reason threads get 
restarted after sometime.

program Project3;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  Winapi.Windows,
  System.SysUtils,
  dwsIOCPWorkerThreadPool,
  IdHTTP;

procedure Download;
var
  HTTP: TIdHttp;
  S: String;
begin
  try
    HTTP := TIdHttp.Create(nil);
    S := HTTP.Get('http://www.somepage.com');
  except

  end;
  WriteLn('Done: ' + GetCurrentThreadId.ToString);
  HTTP.Free;
end;

var
  ThreadPool: TIOCPWorkerThreadPool;
  I: Integer;
begin
  Randomize;
  ReadLn;
  ThreadPool := TIOCPWorkerThreadPool.Create(2);
  for I := 0 to 3 do
  ThreadPool.QueueWork(Download);

  ReadLn;
  ThreadPool.Free;
  ReadLn;
end.

Original issue reported on code.google.com by shadestu...@gmail.com on 24 Jul 2014 at 10:35

GoogleCodeExporter commented 9 years ago
Is creating a TIdHttp thread-safe?

You could try creating your TIdHttp before (in the main thread), and freeing 
them after (in the main thread).

Though you may be better off using mORMot's WinHTTP wrapper for HTTP download 
anyway (and not just because of thread safety!)

Original comment by zar...@gmail.com on 4 Aug 2014 at 9:28

GoogleCodeExporter commented 9 years ago
I am pretty sure this is the Writeln problem. Regards to WinHTTP does that unit 
support 5.1 version?

Original comment by shadestu...@gmail.com on 4 Aug 2014 at 9:30

GoogleCodeExporter commented 9 years ago
Not sure what 5.1 is, I'm using it on Windows 2008 & 2012 R2 servers though.

Original comment by zar...@gmail.com on 4 Aug 2014 at 9:42

GoogleCodeExporter commented 9 years ago
Ah that means WinHTTP 5.1, 
http://msdn.microsoft.com/en-us/library/windows/desktop/aa382925(v=vs.85).aspx

Original comment by shadestu...@gmail.com on 4 Aug 2014 at 9:43

GoogleCodeExporter commented 9 years ago
Ok. Best would be to ask on Synopse/mORMot forum, but WinHTTP 5.1 looks like 
ancient history, so I guess yes.

Original comment by zar...@gmail.com on 4 Aug 2014 at 9:54