Is there a commonly used, "best practice" read-write lock WinAPI implementation? I've only found one implementation and don't know if it's reliable.

有帮助吗?

解决方案

Win32 Critical Sections use some spins before wait. You have only 2 readers thread and rare writes. Just use a single Critical section for the whole thing, and I thing you willl get a very good performance/simplicity ratio. You may want to use RAII idiom to prevent exit path leaving the CS acquired.

其他提示

There's no such lock in WinXP API. You can use shared_mutex from boost. Example. Btw, such locks make sense when you have a lot of readers and a few of occasional writers. If it's not you case - just use mutex (critical section).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top