读/写同步

发布于 2024-07-26 08:26:09 字数 238 浏览 4 评论 0原文

我有一个数据结构,其操作可以分为读操作(例如查找)和写操作(例如插入、删除)。 这些操作应该同步,以便:

  • 在执行写操作时,读操作不能执行(除非在同一线程上),但是读操作可以与其他读操作同时执行。
  • 当读或写操作正在执行时,写操作不能执行(除非在同一线程上)。

这种同步如何实现呢?

该平台是 win-api,因此 api 的同步对象和互锁函数是基本构建块。

I have a data structure whose operations can be categorized as read operations (e.g. lookup) and write operations (e.g. insertion, removal). These operations should be synchronized so that:

  • Read operations can't execute while a write operation is executing (unless on the same thread), however read operations can be executed concurrently with respect to other read operations.
  • Write operations can't execute while either read or write operations are executing (unless on the same thread).

How can this kind of synchronization be implemented?

The platform is win-api so the api's synchronization objects and interlocked functions are the basic building blocks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千仐 2024-08-02 08:26:09

Microsoft 建议的读卡器/写卡器锁实现如下(您必须稍微滚动到标题“读卡器/写卡器锁”):

http://msdn.microsoft.com/en-us/library/ms810427.aspx

仅供参考,供有同样问题但有过问题的人参考.NET 的奢华:

http://msdn.microsoft。 com/en-us/library/system.threading.readerwriterlock.aspx

Microsoft's recommended implementation of a Reader/Writer lock is here (you'll have to scroll a bit, to the header "Reader/Writer locks"):

http://msdn.microsoft.com/en-us/library/ms810427.aspx

For reference, for those who have the same question but who have the luxury of .NET:

http://msdn.microsoft.com/en-us/library/system.threading.readerwriterlock.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文