我可以使用Boost.Geometry.index.rtree线程吗? [英] Can I use Boost.Geometry.index.rtree with threads?

查看:573
本文介绍了我可以使用Boost.Geometry.index.rtree线程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用来自Boost.Geometry的rtree创建多线程空间索引,但是我无法确定这是否是线程安全的。我在rtree.hpp里没有看到任何锁定机制,但我的C ++ / Boost知识是在初学者级别。

I am trying to create a multithreaded spatial index using rtree from Boost.Geometry, however I am unable to determine if this is thread safe. I do not see any locking mechanisms inside rtree.hpp, but my C++/Boost knowledge is at a beginners level.

Boost.Geometry.index.rtree线程安全任何方式?如果没有,什么是最好的方法,以一种安全的方式使用它与多线程(例如互斥锁之间插入()调用?我能够同时查询()insert()?)。

Is Boost.Geometry.index.rtree thread safe in any way? If not, what would be the optimal approach to use it with multiple threads in a safe manner (e.g. mutex lock between insert() calls? Am I able to query() at the same time as insert()?). Specifically I'm trying to get better query (read) performance.

推荐答案


是Boost.Geometry .index.rtree线程以任何方式安全?

Is Boost.Geometry.index.rtree thread safe in any way?


如果没有,最好的方法是用多个线程以安全的方式使用它(例如,插入()之间的互斥锁?

If not, what would be the optimal approach to use it with multiple threads in a safe manner (e.g. mutex lock between insert() calls?

最佳?取决于

您需要互斥,可以使用自旋锁,简单互斥,共享/可升级互斥等。 p>

You need mutual exclusion. You can do this with spinlocks, simple mutex, shared/upgradable mutex etc.


我能够同时查询()insert()?)。

Am I able to query() at the same time as insert()?).

当然不是。这就是所谓的数据竞赛,它是你需要互斥(又名监视器)的第一。

Certainly not. That's called a data race and it's what you need the mutual exclusion (aka monitor) for in the first place.


以获得更好的查询(读取)性能。

Specifically I'm trying to get better query (read) performance.

添加线程不会使事情更快。它使事情更慢。总是。

Adding threads doesn't make things faster. It makes things slower. Always.

诀窍是你可以同时做其他事情。

The trick is that you can do other things at the same time.

您/可以/并行运行多个只读操作。通常,库容器可以安全地从多个线程用于只读操作(尽管您可能想要对隐藏的成员(实现中)中的任何 mutable 执行快速扫描。

You /can/ run multiple read-only operations in parallel. Usually, library containers are safe to use from multiple threads for read-only operations (although you might want to do a quick scan for any mutable members hidden( in the implementation).

这篇关于我可以使用Boost.Geometry.index.rtree线程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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