http://kb.vigal.net/semaphore-mutex-relatio/ Home About Wizard Ray « 在复杂逻辑中尽量使用短小的方 法 FCKEditor 在ASP.NET下的部署笔记 » semaphore与mutex的关系 2009/07/13, 13:03 在多线程编程中,经常使用到如semaphore或mutex等许多线程间同步用的工具,但是mutex和semaphore的区别一直让 人困惑在Pintos Project的实践中,逐渐摸索到一些其中的区别。以下的实现来...
by hdc1112_cu - Linux文档专区 - 2010-02-21 16:41:38 阅读(2613) 回复(0)
Difference between mutex and semaphore Source: http://koti.mbnet.fi/niclasw/mutexsemaphore.html 先看看网上著名的厕所理论的描述: mutex: Is a key to a toilet. One person can have the key - occupy the toilet - at the time. When finished, the person gives (frees) the key to the next person in the queue. Officially: "mutexes are typically used to serialise access to a section of re-entrant code that...
semaphore通过设置计数器,可以实现多个进程间的同步。 event的话,可以设置event标志,当某个标志出现时,等待此标志的线程就可以运行。 那么这两者之间有什么区别?
看起来好象是不一样的,sys/sem.h里申明的是XSI的semaphore, 而semaphore.h里的函数我查了man文档里似乎是有关realtime的,是不是这样呢?请指教?
感觉completion和locked mutex差不多。在之前的版本中,因为up和down没有用spin lock保护。所以semaphore和completion在smp下存在区别。但是在2.6.27中,两者都使用了spin lock保护。那么现在他们还有区别吗?看了下2.6.27的实现,complete会唤醒所有的等待进程,而up只会唤醒一个等待进程。不知道这个是不是它们的区别?其他还有什么不同吗? 谢谢指点。
semaphore在kernel,用户进程和pthread中都用到,这几个semaphore有什么区别吗? [ 本帖最后由 ljshan 于 2009-1-21 16:11 编辑 ]
本帖最后由 okocha-jay 于 2010-06-10 11:00 编辑 大家都知道,volatile修饰的共享变量,是因为它可能被“意外”的改变,比如说在当前执行线程之外被修改; 所以强迫编译器每次都去读内存; 另外,共享变量也可以用mutex来保证线程间互斥访问; mutex保护的变量没必要volatile。 问题: 什么情形下修饰共享变量用volatile, 什么情形用mutex保护? 谢谢
semaphores Remember file locking ? Well, semaphores can be thought of as really generic advisory locking mechanisms. You can use them to control access to files, shared memory , and, well, just about anything you want. The basic functionality of a semaphore is that you can either set it, check it, or wait until it clears then set it ("test-n-set"). No matter how complex the stuff that follo...