thread safety on query functions

Paul elegant_dice at yahoo.com
Wed Nov 18 14:11:32 UTC 2009


2009/11/18 Jason Remillard <remillard.jason at gmail.com>

> Hi,
>
> Sorry if this has been asked before, but I was not able to figure out
> how to search over the list archives.
>
> I would like to build up a kdtree, then spawn multiple threads via
> openmp that will do parallel queries on the tree. The find,
> find_nearest, find_within_range, and visit_within_range are all
> declared as const. However, are they really const?
>  - Does calling them modify the state of the tree in anyway?
>  - Any cached data in the tree?
>  - Any intermediate data stored in the nodes?
>
> If the search functions write to any tree data then concurrent calls
> will not work.
>
>
All the const methods are const-correct, to my knowledge.   This is
important to me too.  Plus, there is no need to write anything during a
search as there is no caching or intermediate data.

Note that your accessor and other classes you use with kdtree will also need
to be thread-safe.

Also note that if you use something like visit_within_range(), the visitor
is *copied* around (like other STL algorithms), so make sure that your
visitor is fast to copy (use pointers or pimpl pattern or letter-envelope
pattern or whatever you want to call it).

see ya
Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/libkdtree-devel/attachments/20091118/4e5d5e0d/attachment.htm>


More information about the libkdtree-devel mailing list