View Issue Details

IDProjectCategoryView StatusLast Update
0004116JEDI VCL00 JVCL Componentspublic2007-12-18 01:52
Reporteradit_boseAssigned Toobones 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionno change required 
Product Version 
Target VersionFixed in Version 
Summary0004116: Bug in JvThread
DescriptionI've used JvThread in my application. While using it, I've found a bug in the ThreadTerminate method, that can be seen in the attached program (Source). On calling JvThread.Terminate after ThreadExecute or ThreadExecuteAndWait, it does NOT terminate. It is Terminated by passing a boolean value (QuitThread).
Additional InformationThe thread is Terminated by passing a boolean value (QuitThread), but this is not the proper way to terminate the thread because, this sample program instantiates on a loop, what if there is no loop?
TagsNo tags attached.

Activities

2007-04-28 23:55

 

ThreadBugSource.zip (361,759 bytes)

AlexB

2007-12-17 02:25

reporter   ~0014079

I can't understand why do you complain about it as bug? It's "as gesigned" (see TThread documentation).

TThread has no method for killing thread in Win32 API TerminateThread style.

Terminate only sets internal flag Terminated and nothing more. Execute must check this flag and exit if Terminated=true.

To use conventional termination mechanism replace Execute method in your progect with

procedure TForm1.JvThread1Execute(Sender: TObject; Params: Pointer);
var
 ThisThread: TJvBaseThread;
begin
  ThisThread:=Sender as TJvBaseThread;
  repeat until ThisThread.Terminated = true;
end;

or with

procedure TForm1.JvThread1Execute(Sender: TObject; Params: Pointer);
begin
  repeat until JvThread1.Terminated = true; // slower
end;

For more information see for example

Subject: TThread sleep and terminate.
Date: Tue, 11 Dec 2007
Message-ID: <475df57e$1@newsgroups.borland.com>

in borland.public.delphi.language.delphi.win32

AHUser

2007-12-17 12:11

developer   ~0014081

Last edited: 2007-12-17 12:16

Terminating a thread with TerminateThread() is dangerous. What if the thread is in a critical section or owns an IPC object (Mutex, Semaphore, ...). Deadlocks will be the result.

jfudickar

2007-12-17 17:13

developer   ~0014083

You can also use the TerminateWaitFor method, which combines the Terminate and the Waitfor procedures.

Added to svn at 18. November.

obones

2007-12-18 01:51

administrator   ~0014084

Well, I then consider this fixed.

Issue History

Date Modified Username Field Change
2007-04-28 23:55 adit_bose New Issue
2007-04-28 23:55 adit_bose File Added: ThreadBugSource.zip
2007-12-16 17:16 AHUser Project JEDI API & WSC Library => JEDI VCL
2007-12-16 17:23 AHUser Category ASPI and SCSI => 00 JVCL Components
2007-12-17 02:25 AlexB Note Added: 0014079
2007-12-17 12:11 AHUser Note Added: 0014081
2007-12-17 12:16 AHUser Note Edited: 0014081
2007-12-17 17:13 jfudickar Note Added: 0014083
2007-12-18 01:51 obones Status new => resolved
2007-12-18 01:51 obones Resolution open => no change required
2007-12-18 01:51 obones Assigned To => obones
2007-12-18 01:51 obones Note Added: 0014084