Skip to content

Is this library thread safe? #3

Closed

Description

@ch541819

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

Activity

  1. ericveach commented on Jan 17, 2018

    @ericveach

    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.

  2. jmr commented on Jan 17, 2018

    @jmr
    Member

    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.

  3. ericveach commented on Jan 17, 2018

    @ericveach
  4. jmr commented on Jan 19, 2018

    @jmr
    Member

    Now documented on S2ShapeIndex as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions