简体   繁体   English

是否存在C ++ 11关键部分?

[英]Are there C++11 critical sections?

I'm trying to find the equivalent of a critical section for C++11 , is the new C++11 mutex concept process-bound (eg enforces mutex only on the user-space) ? 我试图找到相当于C ++ 11的关键部分,是新的C ++ 11互斥锁概念是否受到限制(例如仅在用户空间强制使用互斥锁)? Perhaps it's implementation specific since I cannot find anything specific on it. 也许它是特定的实现,因为我找不到任何特定的东西。 Perhaps C++11 have their own critical section classes as mutexes are cross-process, right? 也许C ++ 11有自己的关键部分类,因为互斥体是跨进程的,对吧? Please help. 请帮忙。

A standard library implementation is free to use any mutex implementation it likes that meets the requirements and behaviors set forth in the standard. 标准库实现可以免费使用它喜欢的任何互斥实现,以满足标准中规定的要求和行为。 An implementation that provides cross-process locking - which the standard doesn't require - would likely be less performant than one that does not. 提供跨进程锁定的实现(标准不需要)可能不会比没有进行锁定的实现更低。 A high-quality implementation will therefore most likely provide process-local mutexes (mutices?). 因此,高质量的实现很可能提供进程本地互斥(mutices?)。

So although one could bang out a conformant implementation of C++11 mutexes using, eg, named semaphores, one would have a hard time selling that implementation to users. 因此,虽然可以使用例如命名的信号量来实现C ++ 11互斥体的一致性实现,但是很难将该实现销售给用户。 To my knowledge no popular implementation exists that provides cross-process locking in std::mutex . 据我所知,还没有流行的实现在std::mutex中提供跨进程锁定。

The C++ standard only concerns single programs, thus a single process; C ++标准只涉及单个程序,因此只涉及一个过程; it has nothing to say about what happens outside of the process. 对于在流程之外发生的事情,没有什么可说的。 At least under some Posix implementations, some "mutex" are cross-process, so under them, any C++ mutex will also be cross-process. 至少在一些Posix实现中,一些“互斥”是跨进程的,因此在它们之下,任何C ++互斥体也将是跨进程的。 Under other systems, it probably depends on the system. 在其他系统下,它可能取决于系统。

Also: implementing the mutex in user space doesn't mean that it can't be cross-process, since user space can include shared memory or mmap ed space, which is accessible from several processes. 另外:在用户空间中实现互斥并不意味着它不能进行跨进程,因为用户空间可以包括共享内存或mmap ed空间,可以从多个进程访问。

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

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