简体   繁体   English

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

[英]Is Perforce's C++ P4API thread-safe?

Simple question - is the C++ API provided by Perforce thread-safe? 简单的问题 - Perforce线程安全提供的C ++ API是什么? 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.? 但是给定一个连接对象,我可以让多个线程获取更改列表,获取状态,通过p4映射翻译文件等吗?

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. 它看起来不像客户端对象具有线程亲和性,因此为了共享线程之间的连接,只需使用互斥锁来序列化调用。

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. 通过麻烦然后在文档中没有提到它是没有意义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM