Results 1 to 2 of 2
Hi,
I have a doubt regarding mutex usage.Can mutex be used for process synchronization?What i know is mutex can be used for thread synchronization.For process synchronization semaphores are used....
- 01-09-2012 #1Just Joined!
- Join Date
- Dec 2011
- Posts
- 5
Mutex for process synchronization
Hi,
I have a doubt regarding mutex usage.Can mutex be used for process synchronization?What i know is mutex can be used for thread synchronization.For process synchronization semaphores are used.
- 01-09-2012 #2
A semaphore and a mutex are essentially the same thing: a mutex is a semaphore with n = 1.
You cannot use mutexes and semaphores across processes because they live in a single process's memory space (though shared memory may be able to get around this). A common cross-process locking mechanism is to use kernel-enforced filesystem locks on lockfiles. For instance:
1) Process A gains exclusive lock on file "./lockfile"
2) Process A begins processing.
3) Process B attempts to gain exclusive lock on file "./lockfile" and blocks.
4) Process A finishes and releases lock on file "./lockfile"
5) Process B gains lock on file "./lockfile" and then does its processing.DISTRO=Arch
Registered Linux User #388732


Reply With Quote