Is THostResolver creating a thread?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Is THostResolver creating a thread?

silvioprog
Hello,

A friend from Brazil found a small problem in "resolve" unit.

Before execute the test:


After execute the test:


And the test is:

procedure TForm1.Button1Click(Sender : TObject);
begin
  with TInetSocket.Create('www.google.com', 80) do
  try
  finally
    Free;
  end;
end;

After debug the TInetSocket class, the problem continues in:

procedure TForm1.Button1Click(Sender : TObject);
begin
 with THostResolver.Create(nil) do
  try
    if not NameLookup('www.google.com') then
      raise Exception.Create('não resolvido');
  finally
    Free;
  end;
end; 

And finally, you can reproduce it with:

uses
  resolve, winsock;

procedure TForm1.Button1Click(Sender: TObject);
var
  FHostEntry: PHostEnt;
begin
  FHostEntry := gethostbyname('www.google.com.br');
end;

But, if in code above I undeclare the "resolve" unit, I got only one thread (threads = 1).

Is this a bug?

Thank you!

--
Silvio Clécio
My public projects - github.com/silvioprog

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Is THostResolver creating a thread?

silvioprog
Oops,

2013/5/8 silvioprog <[hidden email]>
[...]
uses
  resolve, winsock;

procedure TForm1.Button1Click(Sender: TObject);
var
  FHostEntry: PHostEnt;
begin
  FHostEntry := gethostbyname('www.google.com.br');
end;

... gethostbyname('www.google.com') ...

-- 
Silvio Clécio
My public projects - github.com/silvioprog

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Is THostResolver creating a thread?

Michael Van Canneyt


On Wed, 8 May 2013, silvioprog wrote:

> Oops,
>
> 2013/5/8 silvioprog <[hidden email]>
>       [...]
> uses
>   resolve, winsock;
>
> procedure TForm1.Button1Click(Sender: TObject);
> var
>   FHostEntry: PHostEnt;
> begin
>   FHostEntry := gethostbyname('www.google.com.br');
> end;
>
>
> ... gethostbyname('www.google.com') ...
The resolver or netdb units do not create threads by themselves.

But the windows Winsock routines may create threads (I would expect this),
and these may show up in your process manager.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Is THostResolver creating a thread?

silvioprog
2013/5/8 Michael Van Canneyt <[hidden email]>
On Wed, 8 May 2013, silvioprog wrote:
Oops,

2013/5/8 silvioprog <[hidden email]>
      [...]
uses
  resolve, winsock;

procedure TForm1.Button1Click(Sender: TObject);
var
  FHostEntry: PHostEnt;
begin
  FHostEntry := gethostbyname('www.google.com.br');
end;

... gethostbyname('www.google.com') ...

The resolver or netdb units do not create threads by themselves.

But the windows Winsock routines may create threads (I would expect this), and these may show up in your process manager.

Michael.

But my project will always have a thread that is never released? Even when I freed my objects, that thread is still there.

Well, if this is done by the Windows API, I think we have nothing to do hehe...
 
--
Silvio Clécio
My public projects - github.com/silvioprog

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Is THostResolver creating a thread?

zaher dirkey
Maybe it use the thread again, try many requests if there is more threads?


On Wed, May 8, 2013 at 4:35 PM, silvioprog <[hidden email]> wrote:
2013/5/8 Michael Van Canneyt <[hidden email]>
On Wed, 8 May 2013, silvioprog wrote:
Oops,

2013/5/8 silvioprog <[hidden email]>
      [...]
uses
  resolve, winsock;

procedure TForm1.Button1Click(Sender: TObject);
var
  FHostEntry: PHostEnt;
begin
  FHostEntry := gethostbyname('www.google.com.br');
end;

... gethostbyname('www.google.com') ...

The resolver or netdb units do not create threads by themselves.

But the windows Winsock routines may create threads (I would expect this), and these may show up in your process manager.

Michael.

But my project will always have a thread that is never released? Even when I freed my objects, that thread is still there.

Well, if this is done by the Windows API, I think we have nothing to do hehe...
 
--
Silvio Clécio
My public projects - github.com/silvioprog

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal



--
I am using last revision of Lazarus, FPC 2.6 on Windows XP SP3

Best Regards
Zaher Dirkey

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Is THostResolver creating a thread?

silvioprog
2013/5/8 Zaher Dirkey <[hidden email]>
Maybe it use the thread again, try many requests if there is more threads?

It keep only one thread. :)

Sorry Michael, Zaher and friends. A friend tested it in Delphi on Window XP and it's same to Free Pascal.
 
--
Silvio Clécio
My public projects - github.com/silvioprog

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal