Delphi中的线程类--之(2)[6]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 raptor 的 blog

    freethread := thread.ffreeonterminate;

    result := thread.freturnvalue;

    thread.doterminate;

    thread.ffinished := true;

    signalsyncevent;

    if freethread then thread.free;

    endthread(result);

  end;

end;

虽然也没有多少代码,但却是整个tthread中最重要的部分,因为这段代码是真正在线程中执行的代码。下面对代码作逐行说明:

首先判断线程类的terminated标志,如果未被标志为终止,则调用线程类的execute方法执行线程代码,因为tthread是抽象类,execute方法是抽象方法,所以本质上是执行派生类中的execute代码。

所以说,execute就是线程类中的线程函数,所有在execute中的代码都需要当作线程代码来考虑,如防止访问冲突等。

本文关键:Thread Event CriticalSection Synchronize
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top