View Issue Details

IDProjectCategoryView StatusLast Update
0004914JEDI VCL00 JVCL Componentspublic2009-09-14 23:01
ReporterwessonAssigned ToAHUser 
PrioritynormalSeverityblockReproducibilityalways
Status resolvedResolutionfixed 
Product VersionDaily / GIT 
Target VersionFixed in Version3.39 
Summary0004914: [TJvTimerThread] Exception raised when enabling timer thread - solution here
Descriptionin JvThreadTimer.pas, the constructor of TJvTimerThread create a suspended thread, and at the last line of the constructor, the thread is started

(Line 150) :
  {$IFDEF COMPILER14_UP}Start{$ELSE}Resume{$ENDIF COMPILER14_UP};
end;

However, since D2010 all threads are created in suspended state, but there is a "AfterConstruction" method called which start the thread if it was not created in a suspended state.

This change was probably made to make sure that all the constructor will be executed before the thread is really starting. However, this imply that if a thread is created suspended, the "start" method can''t be called from within the constructor, which is the case in the TJvTimerThread object

My Solution is to conditionnally implement an AfterConstruction method that does nothing, which will prevent the start method to be called twice.
Additional InformationAttached patch file does it
TagsJVCL

Activities

2009-09-01 13:29

 

TJvTimerThread_D2010_Fix.patch (1,178 bytes)
Index: run/JvThreadTimer.pas
===================================================================
--- run/JvThreadTimer.pas	(revision 12483)
+++ run/JvThreadTimer.pas	(working copy)
@@ -1,4 +1,4 @@
-{-----------------------------------------------------------------------------
+{-----------------------------------------------------------------------------
 
 The contents of this file are subject to the Mozilla Public License
 Version 1.1 (the "License"); you may not use this file except in compliance
@@ -120,6 +120,9 @@
     constructor Create(ATimer: TJvThreadTimer);
     destructor Destroy; override;
     procedure Stop;
+    {$IFDEF COMPILER14_UP}
+    procedure AfterConstruction; override;
+    {$ENDIF}
     property Interval: Cardinal read FInterval;
     property Timer: TJvThreadTimer read FTimer;
   end;
@@ -134,6 +137,13 @@
 
 //=== { TJvTimerThread } =====================================================
 
+{$IFDEF COMPILER14_UP}
+procedure TJvTimerThread.AfterConstruction;
+begin
+  // Do not call inherited
+end;
+{$ENDIF}
+
 constructor TJvTimerThread.Create(ATimer: TJvThreadTimer);
 begin
   { Create suspended because of priority setting }

AlexB

2009-09-08 11:50

reporter   ~0016058

> since D2010 all threads are created in suspended state,
> but there is a "AfterConstruction" method called which start
> the thread if it was not created in a suspended state.

For your information: v.2007 has the same architecture.

obones

2009-09-09 19:39

administrator   ~0016073

Hello,

We would really like to have the zipped sources of a sample application showing this.

2009-09-10 01:07

 

TJvTimerthreadIssue.7z (3,515 bytes)

wesson

2009-09-10 01:09

reporter   ~0016082

Here you have:

TJvTimerThreadIssue.7z (sevenzip compressed)

Compile, Run, see the crash

Patch, Run, no longer crashes

AHUser

2009-09-14 23:01

developer   ~0016101

Fixed in SVN.
The thread is now created with CreateSuspended=False and the reason for the old implementation, setting the thread priority, is deferred to the Execute() method. That way we are compatible with the old and new TThread class.

Issue History

Date Modified Username Field Change
2009-09-01 13:29 wesson New Issue
2009-09-01 13:29 wesson File Added: TJvTimerThread_D2010_Fix.patch
2009-09-01 13:31 wesson Tag Attached: JVCL
2009-09-08 11:50 AlexB Note Added: 0016058
2009-09-09 19:39 obones Note Added: 0016073
2009-09-09 19:39 obones Status new => feedback
2009-09-10 01:07 wesson File Added: TJvTimerthreadIssue.7z
2009-09-10 01:09 wesson Note Added: 0016082
2009-09-14 23:01 AHUser Note Added: 0016101
2009-09-14 23:01 AHUser Status feedback => resolved
2009-09-14 23:01 AHUser Fixed in Version => Daily / SVN
2009-09-14 23:01 AHUser Resolution open => fixed
2009-09-14 23:01 AHUser Assigned To => AHUser