代码之家  ›  专栏  ›  技术社区  ›  scobi

Perforce的C++ P4API线程安全吗?

  •  3
  • scobi  · 技术社区  · 15 年前

    简单的问题——C++线程API是由线程安全提供的吗?文档中没有提到它。

    “线程安全”是指来自客户机的服务器请求。显然,如果我有多个线程试图在同一个连接上设置客户机名称等,就会出现问题。

    但是给定一个连接对象,我可以让多个线程获取变更列表、获取状态、通过P4映射转换文件等吗?

    2 回复  |  直到 12 年前
        1
  •  10
  •   Raphaël Saint-Pierre    12 年前

    回答晚了,但是…从 release notes 自己:

    已知限制

          The Perforce client-server protocol is not designed to support
          multiple concurrent queries over the same connection. For this
          reason, multi-threaded applications using the C++ API or the
          derived APIs (P4API.NET, P4Perl, etc.) should ensure that a
          separate connection is used for each thread or that only one
          thread may use a shared connection at a time.
    

    它看起来不像客户端对象具有线程关联性,因此为了在线程之间共享连接,只需使用互斥体来序列化调用。

        2
  •  4
  •   Wim Coenen    15 年前

    如果文档没有提到它,那么它是不安全的。

    在任何意义上使某个线程安全通常都是困难的,并且可能由于添加了锁而导致性能损失。解决问题,然后在文档中不提到它是没有意义的。