请问如何创建临界区?(100分)

  • 主题发起人 主题发起人 carem1
  • 开始时间 开始时间
C

carem1

Unregistered / Unconfirmed
GUEST, unregistred user!
给个完整的例子阿~!!包括锁定,和释放;我从来没用过。谢谢啦~!!
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, syncobjs;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; cs: TCriticalSection;<br>&nbsp; &nbsp; procedure mtAccess;<br>&nbsp; public<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; cs := TCriticalSection.Create;<br>end;<br><br>procedure TForm1.mtAccess;<br>begin<br>&nbsp; cs.Enter;<br>&nbsp; try<br>&nbsp; &nbsp; //临界数据访问<br>&nbsp; &nbsp; //...<br>&nbsp; finally<br>&nbsp; &nbsp; cs.Leave;<br>&nbsp; end;<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br>&nbsp; cs.Free;<br>end;<br><br>end.<br>
 
接受答案了.
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
916
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部