View Issue Details

IDProjectCategoryView StatusLast Update
0018089FPCRTLpublic2010-11-28 22:31
ReporterSven Barth Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Platformi386OSWin32 
Product Version2.5.1 
Fixed in Version2.6.0 
Summary0018089: Remove thread_count from the Windows RTLs
DescriptionThe three Windows RTLs contain a variable thread_count which is increased/decreased when a thread attaches or detaches from a DLL. This information is basically useless, as more threads can detach from a DLL than attach (oh wow, we have -3 threads running... oh wait?!).

The variable is not used anywhere else in the RTL or in the packages.
Additional InformationAttached is an example which demonstrates the problem. The main application creates three threads, one before the DLL is loaded and one after. Then two threads are terminated and after a while the third one as well. During the run the thread count of the DLL is written to StdOut. The count looks like the following:
0
2
0
-1

Also attached is a patch which removes the variable.

Note: "Thread_count" is also declared in Native NT and Symbian system units as those were copies from the Win32 RTL originally.
TagsNo tags attached.
Fixed in Revision16472
FPCOldBugId
FPCTarget
Attached Files

Activities

2010-11-28 13:24

 

threadcount.zip (967 bytes)

2010-11-28 13:24

 

rtl-threadcount.patch (3,059 bytes)   
Index: rtl/wince/system.pp
===================================================================
--- rtl/wince/system.pp	(Revision 16450)
+++ rtl/wince/system.pp	(Arbeitskopie)
@@ -57,9 +57,6 @@
   sLineBreak = LineEnding;
   DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
 
-  { Thread count for DLL }
-  Thread_count : longint = 0;
-
 var
 { WinCE Info }
   hprevinst,
@@ -864,14 +861,12 @@
        end;
      DLL_THREAD_ATTACH :
        begin
-         inclocked(Thread_count);
 { Allocate Threadvars ?!}
          if assigned(Dll_Thread_Attach_Hook) then
            Dll_Thread_Attach_Hook(DllParam);
        end;
      DLL_THREAD_DETACH :
        begin
-         declocked(Thread_count);
          if assigned(Dll_Thread_Detach_Hook) then
            Dll_Thread_Detach_Hook(DllParam);
 { Release Threadvars ?!}
Index: rtl/win64/system.pp
===================================================================
--- rtl/win64/system.pp	(Revision 16450)
+++ rtl/win64/system.pp	(Arbeitskopie)
@@ -63,9 +63,6 @@
   sLineBreak = LineEnding;
   DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
 
-  { Thread count for DLL }
-  Thread_count : longint = 0;
-
 type
   TStartupInfo = record
     cb : longint;
Index: rtl/nativent/system.pp
===================================================================
--- rtl/nativent/system.pp	(Revision 16450)
+++ rtl/nativent/system.pp	(Arbeitskopie)
@@ -78,8 +78,6 @@
 
   sLineBreak = LineEnding;
 
-  { Thread count for DLL }
-  Thread_count : longint = 0;
   System_exception_frame : PEXCEPTION_FRAME =nil;
 
 implementation
Index: rtl/win/syswin.inc
===================================================================
--- rtl/win/syswin.inc	(Revision 16450)
+++ rtl/win/syswin.inc	(Arbeitskopie)
@@ -50,8 +50,6 @@
          end;
        DLL_THREAD_ATTACH :
          begin
-           inclocked(Thread_count);
-
            if Win32GetCurrentThreadId <> MainThreadIdWin32 then
            begin
              { Allocate Threadvars  }
@@ -68,7 +66,6 @@
         end;
        DLL_THREAD_DETACH :
          begin
-           declocked(Thread_count);
            if assigned(Dll_Thread_Detach_Hook) then
              Dll_Thread_Detach_Hook(DllParam);
            { Release Threadvars }
Index: rtl/symbian/system.pp
===================================================================
--- rtl/symbian/system.pp	(Revision 16450)
+++ rtl/symbian/system.pp	(Arbeitskopie)
@@ -61,8 +61,6 @@
   sLineBreak = LineEnding;
   DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
 
-  { Thread count for DLL }
-  Thread_count : longint = 0;
   System_exception_frame : PEXCEPTION_FRAME =nil;
 
 type
Index: rtl/win32/system.pp
===================================================================
--- rtl/win32/system.pp	(Revision 16450)
+++ rtl/win32/system.pp	(Arbeitskopie)
@@ -66,8 +66,6 @@
   sLineBreak = LineEnding;
   DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
 
-  { Thread count for DLL }
-  Thread_count : longint = 0;
   System_exception_frame : PEXCEPTION_FRAME =nil;
 
 type
rtl-threadcount.patch (3,059 bytes)   

Florian

2010-11-28 21:47

administrator   ~0043678

Patch applied, thanks for the hint.

Sven Barth

2010-11-28 22:31

manager   ~0043680

You're welcome.

(And here I had thought that I'd need to justify myself more... ^^)

Regards,
Sven

Issue History

Date Modified Username Field Change
2010-11-28 13:24 Sven Barth New Issue
2010-11-28 13:24 Sven Barth File Added: threadcount.zip
2010-11-28 13:24 Sven Barth File Added: rtl-threadcount.patch
2010-11-28 21:47 Florian Fixed in Revision => 16472
2010-11-28 21:47 Florian Status new => resolved
2010-11-28 21:47 Florian Fixed in Version => 2.5.1
2010-11-28 21:47 Florian Resolution open => fixed
2010-11-28 21:47 Florian Assigned To => Florian
2010-11-28 21:47 Florian Note Added: 0043678
2010-11-28 22:31 Sven Barth Status resolved => closed
2010-11-28 22:31 Sven Barth Note Added: 0043680