简体   繁体   中英

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) ? 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? 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?).

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. To my knowledge no popular implementation exists that provides cross-process locking in std::mutex .

The C++ standard only concerns single programs, thus a single process; 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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