Question

I'm after a slim Single-Read Multi-Write lock, similar to TOmniMREW, but that would be less CPU-intensive in cases of contention.

TOmniREW uses only a spinlock, so threads will skyrocket to 100% CPU usage until they can acquire the lock.

Currently I'm using a Critical Section, and while it has less efficient behavior (I have more readers than writers), in case of contention threads relinquish their CPU times.

Contention happens very occasionally in my case, typically when a writer triggers a more complex (lengthy) operation, but when it does, the spinlocks have CPU usage skyrocket.

The Windows SRW implementation uses a similar strategy and is of no help (edit: actually it's about 2-3 times faster in some cases of high contention, but still exhibits the issue edit 2: TOmniMREW will be using SRW when available in future version, so speed will be the same).

Was it helpful?

Solution

Actually after more testing, it appears that Windows SRW does relinquish CPU, it just takes slightly more times for it to do so than I saw in my Critical Sections test.

So Windows SRW are the answer.

OTHER TIPS

Have you read this article: Slim Reader/Writer Locks Rocks ? It also contains a reference to a simple benchmark project of several alternatives

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top