Can I use Boost.Geometry.index.rtree with threads?

若如初见. 提交于 2019-12-11 02:53:59

问题


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.

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.


回答1:


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

No

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?

Optimal? Depends.

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

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.


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).



来源:https://stackoverflow.com/questions/28266656/can-i-use-boost-geometry-index-rtree-with-threads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!