L
lfj125
Unregistered / Unconfirmed
GUEST, unregistred user!
下面这段代码是多人在线游戏有一个玩家退出游戏后向其他玩家发送该玩家下线的消息:
问题:该段代码只有第一个退出的玩家可以安全执行的到(进入.退出临界区),但是以后服务器就有问题了,退出时进入临界区退不出去,后面的人也进不来!求高手给个解决方案!
EnterCriticalSection(CS1);
try
with Clients.LockList do
try
for i := 0 to Clients.LockList.Count-1 do
begin
RecClient := Items;
if RecClient.UserID<>Leave.ManagerID then
begin
Kind.Style := 40;
RecThread := RecClient.Thread;
if not RecThread.Connection.ClosedGracefully then
begin
RecThread.Connection.WriteBuffer(Kind,SizeOf(Kind));
RecThread.Connection.WriteBuffer(Leave,SizeOf(Leave));
end;
end
end;
finally
Clients.UnlockList;
end;
finally
Leavecriticalsection(CS1);
end;
问题:该段代码只有第一个退出的玩家可以安全执行的到(进入.退出临界区),但是以后服务器就有问题了,退出时进入临界区退不出去,后面的人也进不来!求高手给个解决方案!
EnterCriticalSection(CS1);
try
with Clients.LockList do
try
for i := 0 to Clients.LockList.Count-1 do
begin
RecClient := Items;
if RecClient.UserID<>Leave.ManagerID then
begin
Kind.Style := 40;
RecThread := RecClient.Thread;
if not RecThread.Connection.ClosedGracefully then
begin
RecThread.Connection.WriteBuffer(Kind,SizeOf(Kind));
RecThread.Connection.WriteBuffer(Leave,SizeOf(Leave));
end;
end
end;
finally
Clients.UnlockList;
end;
finally
Leavecriticalsection(CS1);
end;