Read - Read/Write Locks They are locks for data structures...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Read/Write Locks They are locks for data structures that can be read by multiple threads simultaneously ( multiple readers ) but that can be modified by only one thread at a time. Example uses: Data Bases, lookup tables, dictionaries etc where lookups are more frequent than modifications.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Read/Write Locks Multiple readers may read the data structure simultaneously Only one writer may modify it and it needs to exclude the readers. Interface: ReadLock() – Lock for reading. Wait if there are writers holding the lock ReadUnlock() – Unlock for reading WriteLock() - Lock for writing. Wait if there are readers or writers holding the lock
Background image of page 2
Read/Write Locks Threads: R1 R2 R3 R4 W1 --- --- --- --- --- RL RL RL WL wait RU RU RU continue RL Wait rl = readLock; ru = readUnlock; wl = writeLock; wu = writeUnlock;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Read/Write Locks Implementation class RWLock { int _nreaders; //Controls access //to readers/writers sema_t _semAccess; mutex_t _mutex; public: RWLock(); void readLock();
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

Read - Read/Write Locks They are locks for data structures...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online