zoukankan      html  css  js  c++  java
  • DELPHI跨平台的临界替代者

    在WINDOWS里面使用临界来保护多线程需要访问的共享对象,现在,DELPHI有了新的跨平台临界保护者--System.TMonitor

    代码演示如下:

    FConnections := TObjectDictionary<TIdTCPConnection,TDSTCPChannel>.Create;

    。。。

    procedure TCMServerForm.CMServerTransportDisconnectEvent(Event: TDSTCPDisconnectEventObject);
    var
    Index: Integer;
    begin
    if (FConnections = nil) or (Event.Connection = nil) then
    Exit;

    //进入临界保护
    System.TMonitor.Enter(FConnections);
    try
    FConnections.Remove(TIdTCPConnection(Event.Connection));

    TThread.Synchronize(nil, procedure
    begin
    //update the connection list box, removing the connection that was just closed
    Index := ConnectionsList.Items.IndexOfObject(Event.Connection);
    if Index > -1 then
    begin
    ConnectionsList.Items.Delete(Index);

    if ConnectionsList.SelCount = 0 then
    SessionIdList.ClearSelection;
    end;
    end);
    finally

    // 终止临界保护
    System.TMonitor.Exit(FConnections);
    end;
    end;

  • 相关阅读:
    Linux——端口命令
    Linux——iptables 禁止 IP和端口
    CE第9关共用
    获得程序窗体标题-FindWindowW需要的参数
    mysql ODBC win10 设置
    Work
    Pet
    Is It A Tree?
    Ice_cream's world I
    小希的迷宫
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/5670707.html
Copyright © 2011-2022 走看看