_nolock CRT 函数

发布于 2024-07-10 22:37:22 字数 307 浏览 5 评论 0原文

我最近发现 _nolock 函数 的存在,我很惊讶我能找到的关于这些的信息是如此之少。 它说它可以提高性能,但我找不到任何基准。 它还说,如果程序自己锁定,它们可以在多线程程序中使用,但是必须锁定什么? 所有 CRT 调用都应该经过同一个锁吗? 每个功能一个? 每组功能一个? 如果是这样,什么定义了群体?

您能给我提供有关这些功能的一些详细信息吗? 谢谢 :-)

I have recently discovered the existence of _nolock functions, and I am surprised by how little info I can find on these. It says it increases performance, but I can't find any benchmark. It also says they can be used in a multi-threaded program if the program does its own locking, but what has to be locked? Should all CRT calls go through the same lock? One per function? One per group of functions? If so, what defines groups?

Could you point me to some detailed information about these functions? Thanks :-)

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

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

发布评论

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

评论(2

流年里的时光 2024-07-17 22:37:22

如果从多个线程访问文件,则需要锁定对该文件的访问。 否则,一个线程可能会在另一个线程的中间写入。 通过打印到 stdio 来尝试它们以查看效果。

You need to lock access to the file if you are accessing it from multiple threads. Otherwise, one thread could write right in the middle of another one. Try them out by printing to stdio to see the effects.

烈酒灼喉 2024-07-17 22:37:22

如果您点击各个函数的链接,您将看到以下行:

仅在线程安全中使用此函数
诸如单线程之类的上下文
应用程序或调用的地方
范围已经处理线程
隔离。

衡量性能差异的唯一方法是创建一个小程序并对其进行测试。 正如 monjardin 指出的那样,您需要锁定对使用该函数访问的文件的访问(除非,如文档中所述,您处于单线程环境中)。

If you follow the links to the individual functions, you'll see the following line:

Use this function only in thread-safe
contexts such as single-threaded
applications or where the calling
scope already handles thread
isolation.

The only way to benchmark the performance difference would be to create a small program and test it out. As monjardin pointed out, you need to lock access to the file you're accessing with the function (unless, as noted in the documentation, you are in a single-threaded environment).

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