Difference between mutex and semaphore
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A mutex has two possible states: unlocked (not owned by any thread), and locked (owned by one thread). A mutex can never be owned by two different threads simultaneously. A thread attempting to lock a mutex that is already locked by another thread is suspended until the owning thread unlocks the mutex first.
Example -
A shared global variable x can be protected by a mutex as follows:
int x;
pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
All accesses and modifications to x should be bracketed by calls to pthread_mutex_lock and pthread_mutex_unlock as follows:
pthread_mutex_lock(&mut);
/* operate on x */
pthread_mutex_unlock(&mut);
TBD
Is it possible to implement semaphores without special machine instructions(compare and swap instruction(IBM 370) or atomic read
and clear instruction(AT &T 3B20))?
YES - Bach Chapter 12 Multiprocessor Systems
Blog Archive
-
▼
2007
(55)
-
▼
Apr
(48)
- Socket Programming
- Pthreads
- Virtual Memory Management
- How a system call is implemented?
- Inter-process communication
- How malloc has been implemented (brk system call)?
- Linux Modules - How are they linked dynamically?
- Proc File System
- fork, vfork, copy-on-write and clone
- CPU Scheduling -- Different types of CPU schedulin...
- Signals (System V and POSIX)
- How mapping from virtual address address to physic...
- setuid program (real and effective user ids)
- Exceptions, traps, interrupts and signals
- Processor execution levels
- Process Address Space
- Unix/Linux File System Layout
- Salient points about Unix/Linux
- Big Endian versus Little Endian
- Semaphore, Mutex, Conditional variable, Spin lock
- Segmentation Fault and Bus Error
- wait() system call
- Bottom half
- Linux time keeping - Timer interrupt, jiffies, xtime
- Position Independent Code (PIC)
- kmalloc/kfree and vmalloc/vfree
- Static versus shared objects
- How many processes will be created-- fork?
- Can we get return value from exec system call?
- How does profiling code works? -- processor debug ...
- ptrace - how does it work?
- Record locking
- GNU Linux pthreads
- How do you use RSA for both authentication and sec...
- Unix/Linx bootupand login
- What are various problems unique to distributed da...
- cooperative,preemption,non preemption
- Puzzles
- Write system call that prints stack trace at that ...
- DMA (Direct Memory Access)
- Real Time Systems
- Comparison of IOS and General Purpose OS like Linux
- Operating Systems I/O Structure
- Linux - Process Scheduling
- Deadlock avoidance and prevention
- Porting from 32 bit OS to 64 bit OS
- Sign extension
- How to make an application daemon
-
▼
Apr
(48)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment