#include <linux/spinlock.h> rwlock_t m; read_lock(m); // critical section read_unlock(m); write_lock(m); // critical section write_unlock(m);
-rwlock support in windows(.NET), Java, POSIX…
-read/write == shared/exclusive
semantic differences
-recursive read.lock … -> what happens on read.unlock
Monitors specify…
-shared resource
-entry procedure
-possible condition variables
On entry
-lock, check…
On exit
-unlock, check,signal
Monitors==high-level synchronization construct
-mesa by xerox parc
-java
Monitors == programming style
– enter / exit_critical section in threads
More Synchronization Constructs
spinlock, monitor, rwlock, condition variable, mutex, path expression, serializers
spinlock => basic sync construct
-alternative implementations of spinlocks
– generalize techniques
spinlock_init(lock): lock = free; spinlock_lock(lock): spin: if(lock == free){ lock = busy; } else { goto spin; } spinlock_unlock(lock): lock = free;
caches
– hide memory latency; memory “further away” due to contention