Subj : Re: Diff b/w Events, Semaphores and mutex To : comp.programming.threads From : David Schwartz Date : Tue Apr 26 2005 11:22 am "Gurikar" wrote in message news:1114486170.187065.122810@f14g2000cwb.googlegroups.com... > Thank you david, > Mutex: A lock that only one thread can hold. These are used to ensure > > that only a single thread accesses a shared object at a time. > > Mutex can only lock shared object but not particluar piece of code. > Is it? A mutex can lock anything. Normally it doesn't make sense to lock code. > Semaphores: A number. You can increase the number, decrease the number, > or do a "wait and decrement" operation. They can be used to ensure that > no > more than a particular number of threads (which can be one) can access > a > particular resource. > What do you mean particluar resource, is it a object or piece of > object. It can be anything, so long as everyone agrees what it is. > One more thing what to use when your doing inter thread communication > and what to used when doing inter process communication? All threads share all memory, so inter-thread communication is a cinch. You usually don't have to do anything special, just let the threads operate on the same data. Just make sure to use appropriate synchronization primitives to ensure there's no corruption. You seem to not quite get the basics of thread synchronization. Maybe someone has a good reference to a web page that explains it. The idea is that you don't want two threads accessing the same data at the same time, so you associate an exclusive lock of some sort with that data. The lock doesn't have to know what data it goes to. DS .