A reader-writer lock object has operations unlock() (to unlock a read or writer
ID: 3866493 • Letter: A
Question
A reader-writer lock object has operations unlock() (to unlock a read or writer lock), lock_read() (to acquire a lock for reading), lock_write() (to get a writer lock).
Assuming that a reader lock blocks a writer, then what is the correct sequence of calls to a reader-writer lock rwlock to protect this critical section involving a shared variable counter:
counter++
- rwlock.lock_read();
counter++;
rwlock.unlock()
- rwlock.lock_write();
rwlock.lock_read();
counter++;
rwlock.unlock()
rwlock.unlock()
- rwlock.lock_write();
counter++;
rwlock.unlock()
- rwlock.lock_read();
counter++;
rwlock.unlock()
Explanation / Answer
The correct option is as follows:
rwlock.lock_write();
counter++;
rwlock.unlock()
The reason behind this is tht rwlock.unlock() is responsible for guarding the critical section with the help of the rwWriteLock. It ensures that the ReadWriteLock will lock the other threads in the program.
Hence , the above option is correct.
Please rate the answer if it helped.......Thankyou
Hope it helps....
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.