Differences between Conditional variables, Mutexes and Locks

后端 未结 3 1195
一个人的身影
一个人的身影 2020-12-22 19:11

For example the c++0x interfaces

I am having a hard time figuring out when to use which of these things (cv, mutex and lock). Can anyone please explain or point to a

3条回答
  •  温柔的废话
    2020-12-22 19:52

    I'm not too familiar w/ C++0x so take this answer w/ a grain of salt.

    re: Mutex vs. locks: From the documentation you posted, it looks like a mutex is an object representing an OS mutex, whereas a lock is an object that holds a mutex to facilitate the RAII pattern.

    Condition variables are a handy mechanism to associate a blocking/signaling mechanism (signal+wait) with a mutual exclusion mechanism, yet keep them decoupled in the OS so that you as system programmer can choose the association between condvar and mutex. (useful for dealing with multiple sets of concurrently-accessed objects) Rob Krten has some good explanations on condvars in one of the online chapters of his book on QNX.

    As far as general references: This book (not out yet) looks interesting.

提交回复
热议问题