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

发布于 2024-09-02 06:16:39 字数 177 浏览 1 评论 0原文

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

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

但是给定一个连接对象,我可以有多个线程来获取更改列表、获取状态、通过 p4 映射翻译文件等吗?

Simple question - is the C++ API provided by Perforce thread-safe? There is no mention of it in the documentation.

By "thread-safe" I mean for server requests from the client. Obviously there will be issues if I have multiple threads trying to set client names and such on the same connection.

But given a single connection object, can I have multiple threads fetching changelists, getting status, translating files through a p4 map, etc.?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素罗衫 2024-09-09 06:16:39

迟到的答案,但是...来自发行说明他们自己:

已知限制

      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.

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

Late answer, but... From the release notes themselves:

Known Limitations

      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.

It does not look like the client object has thread affinity, so in order to share a connection between threads, one just has to use a mutex to serialize the calls.

失与倦" 2024-09-09 06:16:39

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

使某些东西在任何意义上都是线程安全的通常很困难,并且可能会因为添加锁而导致性能损失。经历了这个麻烦然后不在文档中提及它是没有意义的。

If the documentation doesn't mention it, then it is not safe.

Making something thread-safe in any sense is often difficult and may result in a performance penalty because of the addition of locks. It wouldn't make sense to go through the trouble and then not mention it in the documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文