浏览代码

* don't access the thread instance after calling DoTerminate to avoid
race conditions in case DoTerminate can cause the thread to be freed
already. Side-effect: changing FreeOnTerminate in DoTerminate no longer
has any effects, but this is compatible with the generic code for
ThreadProc in objpas/classes/classes.inc (patch by Nikolai ZHUBR)

git-svn-id: trunk@14504 -

Jonas Maebe 15 年之前
父节点
当前提交
b214448b9e
共有 1 个文件被更改,包括 3 次插入1 次删除
  1. 3 1
      rtl/unix/tthread.inc

+ 3 - 1
rtl/unix/tthread.inc

@@ -85,6 +85,7 @@ end;
 function ThreadFunc(parameter: Pointer): ptrint;
 var
   LThread: TThread;
+  LFreeOnTerminate: boolean;
 {$ifdef DEBUG_MT}
   lErrorAddr, lErrorBase: Pointer;
 {$endif}
@@ -143,8 +144,9 @@ begin
   Result := LThread.FReturnValue;
   WRITE_DEBUG('Result is ',Result);
   LThread.FFinished := True;
+  LFreeOnTerminate := LThread.FreeOnTerminate;
   LThread.DoTerminate;
-  if LThread.FreeOnTerminate then
+  if LFreeOnTerminate then
     begin
       WRITE_DEBUG('Thread ',ptruint(lthread),' should be freed');
       LThread.Free;