delphi关于线程安全问题
来源:互联网 发布:火影忍者八项数据 编辑:程序博客网 时间:2024/05/30 22:59
TThread提供了几种同步的方法:
TThread = class
protected
procedure Synchronize(Method: TThreadMethod); overload; // 在继承中调用同步
public
class procedure Synchronize(AThread: TThread; AMethod: TThreadMethod); overload;
class procedure StaticSynchronize(AThread: TThread; AMethod: TThreadMethod);
end;
OnTerminate事件是线程安全的。
TServerSocket
当TServerSocket的ServerType设置为stThreadBlocking方式时,要注意
OnAccept: 线程安全
OnGetThread: 线程安全
OnThreadStart : 线程不安全
OnThreadEnd : 线程不安全
OnClientConnect: 线程不安全(好象没被调用)
OnClientDisconnect: 线程不安全
OnClientRead: 线程安全
OnClientWrite: 线程安全
OnClientError: 线程不安全
参考代码:
procedure TServerClientThread.Execute;
begin
FServerSocket.ThreadStart(Self);
try
try
while True do
begin
if StartConnect then ClientExecute;
if EndConnect then Break;
end;
except
HandleException;
KeepInCache := False;
end;
finally
FServerSocket.ThreadEnd(Self);
end;
end;
procedure TServerClientThread.ClientExecute;
var
FDSet: TFDSet;
TimeVal: TTimeVal;
begin
while not Terminated and ClientSocket.Connected do
begin
FD_ZERO(FDSet);
FD_SET(ClientSocket.SocketHandle, FDSet);
TimeVal.tv_sec := 0;
TimeVal.tv_usec := 500;
if (select(0, @FDSet, nil, nil, @TimeVal) > 0) and not Terminated then
if ClientSocket.ReceiveBuf(FDSet, -1) = 0 then Break
else Synchronize(DoRead);
if (select(0, nil, @FDSet, nil, @TimeVal) > 0) and not Terminated then
Synchronize(DoWrite);
end;
end;
- delphi关于线程安全问题
- 关于servlet线程安全问题
- 关于sheet线程安全问题
- 关于Servlet线程安全问题
- 关于同步线程安全问题
- 关于线程安全问题
- 关于java线程安全问题
- 关于servlet的线程安全问题
- 关于Java OutputStream 线程安全问题
- java 关于SimpleDateFormat线程安全问题
- 关于NSDateFormatter的线程安全问题
- 关于servlet的线程安全问题
- 关于struts中Action是否线程安全问题?
- JAVA中关于线程通信安全问题
- 关于MINA框架的线程安全问题
- 关于Java语言中的线程安全问题
- 关于单例模式线程安全问题
- 关于java中的StringBuilder的线程安全问题
- ORACLE 中TO_DATE()的用法
- [效果]JS折叠菜单-moo.fx.js
- [效果]JS折叠菜单-moo.fx.pack.js
- [转帖]IT人不可不听的10个故事
- [效果]JS折叠菜单-prototype.lite.js
- delphi关于线程安全问题
- Beginning C# Objects从概念到代码——1.13 代码块和变量作用范围
- CSDN读书-态度决定一切
- 媲美Flash的JS导航菜单
- 通信和通讯的区别
- 大教堂与市集
- 为什么是Firefox?
- 最近调试的javamail
- Visual C#学习笔记 - Main方法