🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.language.objectpascal
Article #38

multithreaded exe -> dll = problems terminating threads

#38
From: jonsjostedt
Date: Thu, 18 Aug 2005 11:20
66 lines
2185 bytes
Hi all!
When using below code in an application (.exe) it works fine, but
moving it to a .DLL, the SillyThread wont terminate if i put some
breakpoints in the thread and/or in the mainthread. Any ideas on this
appreciated





unit Unit1;

interface

implementation

uses
  Classes, SysUtils, SyncObjs;

type
  TSillyThread = class(TThread)
  protected
    procedure Execute; override;
  public
    SimpleEvent: TSimpleEvent;

    constructor Create;
    destructor Destroy; override;
  end;

var
  SillyThread: TSillyThread;
{ TSillyThread }

constructor TSillyThread.Create;
begin
  inherited Create(True);
  SimpleEvent := TSimpleEvent.Create;
  Resume;
end;

destructor TSillyThread.Destroy;
const
  INFINITY = $FFFFFFFF;
begin
  Terminate;
  //WaitFor; //Does not work. Seams to require a messageloop which
there are none in a DLL
  SimpleEvent.WaitFor(INFINITY);
  SimpleEvent.Free;

  inherited Destroy;
end;

procedure TSillyThread.Execute;
begin
  while not Terminated do
    Sleep(1000);
  SimpleEvent.SetEvent;
end;

initialization
  SillyThread := TSillyThread.Create;
finalization
  SillyThread.Free;
end.
Technical Details
Message-ID: <1124364044.585080.87140@g14g2000cwa.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g14g2000cwa.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 109d30,3e6890610669a836,start
X-Google-Attributes: gid109d30,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g14g2000cwa.googlegroups.com!not-for-mail
From: jonsjostedt@hotmail.com
Newsgroups: borland.public.delphi.language.objectpascal
Subject: multithreaded exe -> dll = problems terminating threads
Date: 18 Aug 2005 04:20:44 -0700
Organization: http://groups.google.com
Lines: 67
Message-ID: <1124364044.585080.87140@g14g2000cwa.googlegroups.com>
NNTP-Posting-Host: 217.209.224.128
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1124364049 25810 127.0.0.1 (18 Aug 2005 11:20:49 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 18 Aug 2005 11:20:49 +0000 (UTC)
User-Agent: G2/0.2
Complaints-To: groups-abuse@google.com
Injection-Info: g14g2000cwa.googlegroups.com; posting-host=217.209.224.128;
   posting-account=K4416Q0AAAASkqKFFUdXYZVISe4hmKci