现在,有两个线程需要使用这两个互斥量。
Now, imagine that two threads want to use them. Thread one does this.
如果可能,在设计程序时决不要锁定一个已经锁定的互斥量。
If possible, just design your program never to re-lock a mutex it already has.
如果线程2要运行,它就要锁定count _ mutex,而这个互斥量已经被线程1占有了。
If thread two runs, it'll want to lock count_mutex, which is held by thread one.
如果线程1要运行,它就要锁定rand _ mutex,可是这个互斥量已经被线程2阻塞了。
If thread one runs, it'll want to lock rand_mutex, which is held by thread two.
在厕所里重要的例子二进制信号量互斥的区别?
Difference between Binary Semaphore and Mutex in the toilet key example?
在厕所里重要的例子二进制信号量互斥的区别?
Difference between Binary Semaphore and Mutex in the toilet key example?
应用推荐