delphi 线程

来源:互联网 发布:代码淘宝模板多少钱 编辑:程序博客网 时间:2024/05/22 13:24

unit threadutil;

interface
uses classes,windows;
type
TLock=class
  private FLock: TRTLCriticalSection;
  public constructor create;
  public procedure lock;
  public procedure unlock;
end;
TBaseThread=class(TThread)
  public test:integer;
  public onwork:TNotifyEvent;
  procedure execute;override;
end;

implementation
constructor TLock.create;
begin
  InitializeCriticalSection(FLock);
end;
procedure TLock.lock;
begin
  EnterCriticalSection(FLock);
end;
procedure TLock.unlock;
begin
  LeaveCriticalSection(FLock);
end;

procedure TBaseThread.execute;
begin
  if assigned(onwork) then
    onwork(self);
end;

end.