设为首页 加入收藏

TOP

Delphi 高效读写锁(二)
2017-10-10 12:06:24 】 浏览:1327
Tags:Delphi 高效 读写
ngleWriteLocker Error'); TInterlocked.Add(FLocker, -$10000); end; procedure TMultiReadSingleWriteLocker.UnLockRead; begin TInterlocked.Decrement(FLocker); end; constructor TMultiReadSingleWriteLocker.Create; begin FLocker := 0; end; { TSimpleLocker } procedure TSimpleLocker.Lock; var Wait: TSpinWait; begin Wait.Reset; while True do begin if FLocker = 0 then begin if TInterlocked.CompareExchange(FLocker, 1, 0) = 0 then Exit; end; Wait.SpinCycle; end; end; function TSimpleLocker.TryLock: Boolean; begin if FLocker = 0 then begin Result := TInterlocked.CompareExchange(FLocker, 1, 0) = 0; end else Result := False; end; procedure TSimpleLocker.UnLock; begin if TInterlocked.CompareExchange(FLocker, 0, 1) <> 1 then raise Exception.Create('TSimpleLocker Error'); end; end.

  

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇[教学] Firemonkey 之 StringGrid.. 下一篇[教学] Firemonkey TImageList 加..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目