信号量TSemaphore
信号量TSemaphore
uses syncobjs;
TSemaphore = class(THandleObject) {$IF Defined(LINUX) or Defined(ANDROID)} private FSem: sem_t; {$ENDIF LINUX or ANDROID} {$IFDEF MACOS} private FSem: dispatch_semaphore_t; {$ENDIF MACOS} public constructor Create(UseCOMWait: Boolean = False); overload; constructor Create(SemaphoreAttributes: PSecurityAttributes; AInitialCount, AMaximumCount: Integer; const Name: string; UseCOMWait: Boolean = False); overload; constructor Create(DesiredAccess: Cardinal; InheritHandle: Boolean; const Name: string; UseCOMWait: Boolean = False); overload; {$IFDEF POSIX} destructor Destroy; override; function WaitFor(Timeout: Cardinal = INFINITE): TWaitResult; override; {$ENDIF POSIX} procedure Acquire; override; procedure Release; overload; override; function Release(AReleaseCount: Integer): Integer; reintroduce; overload; end;
可以看出,此类是支持跨平台的,不知始于哪个DELPHI版本,反正DELPHI7是没有这个类的。
var MySemaphore: TSemaphore; MySemaphore := TSemaphore.Create(nil, StrToInt(Edit1.Text), 5, ''); if MySemaphore.WaitFor(INFINITE) = wrSignaled then begin ...... end; MySemaphore.free;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/14111942.html