多线程同步问题 [英] multi thread sync question

查看:92
本文介绍了多线程同步问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我正在处理多线程应用程序.我没有提供任何代码,因为我还没有启动它.我试图找出如何同步数据访问.这将是一个数据树.多个线程可以同时读取该树.但是,一旦线程需要删除节点,就必须锁定所有读取访问权限,直到删除完成.而且一次只能有一个线程删除一个节点.从我的所有研究中,我找到了一种方法,允许通过使用互斥锁一次访问一个线程以进行读取或删除.但是我还没有找到一种在删除时锁定读取的同时允许多个读取的方法.如果有人能指出我的正确方向.好的教程对我有很大帮助.谢谢

Okay I am working on a multithreaded application. I dont have any code to provide as I havent started it. Im trying to find out how to sync data access. It is going to be a data tree. The tree can be read by multiple threads at the same time. But as soon as a thread need to delete a node all read access need to be locked until the delete is complete. And only one thread can delete a node at a time. From all my research I have found ways to allow one thread access at a time for read or delete through use of mutex. But I havent found a way to allow multiple reads at the same time while locking reads while deleting. If someone could just point me in a good direction. To a good tutorial that would help me greatly. Thanks

推荐答案

您可以使用:
ACE_RW_Thread_Mutex [ boost :: shared_mutex [ ^ ]

提升首页 [ ^ ]
Ace主页 [
You could use:
ACE_RW_Thread_Mutex[^] or boost::shared_mutex[^]

Boost homepage[^]
Ace homepage[^]

Best regards
Espen Harlinn


您遇到的是经典的多读取器/单写入器锁定"问题.许多人为此撰写了文章和解决方案.

必应搜索 [
What you have is the classic "Multiple Readers / Single Writer Lock" problem. Lots of people have written articles and solutions to this.

Bing Search[^] will reveal many sources of information and algorithms to implement that.


在我的所有研究中,我找到了一种方法,允许一次使用互斥量一次访问一个线程以进行读取或删除.但是我还没有找到一种在删除时锁定读取的同时允许多次读取的方法.

读取节点永远不需要同步.
仅当您尝试删除或修改节点时.如果它在进程内,则可以使用关键部分从树中删除节点.
From all my research I have found ways to allow one thread access at a time for read or delete through use of mutex. But I havent found a way to allow multiple reads at the same time while locking reads while deleting.

Reading the node would never need sync-ing.
It''s only when you try to delete or modify the node. If it''s within process you could use critical section to remove nodes from the tree.


这篇关于多线程同步问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆