Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this library thread safe? #3

Closed
ch541819 opened this issue Jan 16, 2018 · 4 comments
Closed

Is this library thread safe? #3

ch541819 opened this issue Jan 16, 2018 · 4 comments

Comments

@ch541819
Copy link

Is S2PointIndex thread safe? Should I use mutex when S2PointIndex.Add() and S2ClosestPointQuery.query() are called simultaneously in multithread?

@ericveach
Copy link

Unless otherwise documented, all S2 classes have the same thread-safety properties as std::vector: const methods are thread-safe, and non-const methods are not thread-safe.

So for example you issue multiple queries at the same time, but updates to the index cannot overlap any other operations.

@jmr
Copy link
Member

jmr commented Jan 17, 2018

This is documented on MutableS2ShapeIndex:

// Locking is used to ensure that MutableS2ShapeIndex
// has the same thread-safety properties as "vector": const methods are
// thread-safe, while non-const methods are not thread-safe.  This means that
// if one thread updates the index, you must ensure that no other thread is
// reading or updating the index at the same time.

@ericveach Should we add something similar on S2ShapeIndex? The Minimize() comment implies this, but it's easy to miss.

@ericveach
Copy link

ericveach commented Jan 17, 2018 via email

@jmr
Copy link
Member

jmr commented Jan 19, 2018

Now documented on S2ShapeIndex as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants