Exercise 3: Working with the reader_writer_lock (Background)
Figure 1
In the previous exercise we showed you the motivation behind using the concurrency runtime’s synchronization primitives. You learned how the critical_section could be used to synchronize shared date between threads. If you are ever faced with a scenario where you have multiple readers and very few writers, then using a critical_section when readers read the variable might not be the best idea. The Concurrency Runtime introduces a new class called the reader_writer_lock that can be of great help when working with such scenarios. The reader_writer_lockThis class enables multiple threads to read from a shared resource at the same time but only allows one thread to write to it at a time. They share many characteristics with concurrency runtime’s critical section, reader writer locks are non-reentrant and block cooperatively. The reader writer lock resembles the Win32 Slim reader/writer locks (SRWLock). The reader_writer_lock performs better than critical section in read-mostly environments. Similarity to Win32 Slim reader/writer locks
Differences with Win32 Slim reader/writer locks:
|
DownloadsDownload The Offline Training Kit Contents
|