简体   繁体   English

std::lock_guard 可以中断吗?

[英]Can std::lock_guard be interupted?

If I have some code under lock_guard like:如果我在 lock_guard 下有一些代码,例如:

std::thread t([&]()
{
    std::lock_guard<std::mutex> lock(m);
    // some simple operations
});

Do I have a guarantee that "some operations" will never be interrupted on this core cpu that t thread is running?我是否保证“某些操作”永远不会在t线程正在运行的这个核心 cpu 上被中断? Can there be context switching after lock_guard? lock_guard 之后可以进行上下文切换吗?

会有上下文切换,但可以保证所有其他线程都将被锁定在锁后面。

No, a critical section protected by a mutex is not going to run with real-time priority unless you explicitly request it to do so, which cannot be done using the standard C++ library.不,受互斥锁保护的临界区不会以实时优先级运行,除非您明确要求这样做,而使用标准 C++ 库无法做到这一点。 The kernel can still schedule another thread (in the same process, or some other process) that isn't waiting on the mutex.内核仍然可以调度另一个不在互斥锁上等待的线程(在同一个进程或其他某个进程中)。 Setting real-time priority can only be done with OS-specific system calls.设置实时优先级只能通过特定于操作系统的系统调用来完成。

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

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