[FEATURE REQUEST] Turning the TEncoding into thread-safe
Original Reporter info from Mantis: silvioprog
-
Reporter name: silvioprog
Original Reporter info from Mantis: silvioprog
- Reporter name: silvioprog
Description:
Hello,
The TEncoding class has some useful singletons as class property on its public section, however, currently it isn't thread-safe.
Steps to reproduce:
Just compile and test the code below:
program project1; {$IFDEF FPC} {$MODE DELPHI} {$ENDIF} {$IFDEF MSWINDOWS} {$APPTYPE CONSOLE} {$ENDIF} uses // HeapTrc, the FPC staff recomends to enable HeapTrc in the lpi or passing the -gh compiler parameter {$IFDEF UNIX} CThreads, {$ENDIF} SysUtils, Classes; type TTestThread = class(TThread) public constructor Create; procedure Execute; override; end; constructor TTestThread.Create; begin inherited Create(True); FreeOnTerminate := False; end; procedure TTestThread.Execute; begin WriteLn(TEncoding.Default.GetString(TBytes.Create(65, 66, 67))); end; var VThread1, VThread2: TTestThread; begin {$IFNDEF FPC} ReportMemoryLeaksOnShutdown := True; {$ENDIF} VThread1 := TTestThread.Create; VThread2 := TTestThread.Create; try Sleep(1000); VThread1.Start; VThread2.Start; VThread1.WaitFor; VThread2.WaitFor; finally VThread1.Free; VThread2.Free; end; end.
Additional information:
If you compile and run the code above, you may get the following trace:
ABC ABC Heap dump by heaptrc unit 44 memory blocks allocated : 2119/2144 43 memory blocks freed : 2087/2112 1 unfreed memory blocks : 32 True heap size : 131072 True free heap : 131072 Should be : 130912 Call trace for block $00007FFFF7FAB0C0 size 32
Mantis conversion info:
- Mantis ID: 30462
- Version: 3.1.1
- Fixed in revision: 34483 (#b504cc41)