Table of Contents Previous Next
Logo
Threads and Concurrency with C++ : 31.9 Efficiency Considerations
Copyright © 2003-2007 ZeroC, Inc.

31.9 Efficiency Considerations

The mutual exclusion mechanisms provided by Ice differ in their size and speed. Table 31.1 shows the relative sizes for Windows and Linux (both on Intel architec­tures).
Table 31.2 shows the relative performance of the different synchronization primi­tives under conditions of no lock contention.
12.24 (read lock)
22.45 (write lock)
3.23 (read lock)
3.40 (write lock)
Note that the size and performance differences between a mutex and a recursive mutex are negligible, so you should use a non-recursive mutex only if you have a very small critical region that is accessed repeatedly in a tight loop. Similarly, monitors perform much the same as mutexes (but do have a size penalty).
Read-write locks incur a substantial cost in both size and speed (especially under Windows), so you should use a read-write lock only if you can truly exploit the additional parallelism afforded by multiple readers and if a substantial amount of work is performed inside the critical region.
Table of Contents Previous Next
Logo