Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

document concurrency properties #110

Open
bradfitz opened this issue Dec 31, 2020 · 3 comments
Open

document concurrency properties #110

bradfitz opened this issue Dec 31, 2020 · 3 comments

Comments

@bradfitz
Copy link
Contributor

We should document what methods are safe to call concurrently.

In general things aren't safe (and that's the default to assume in Go when not documented otherwise), but we have plenty of stuff that is safe to call concurrently. Anything on a value type, for instance. And the func returned by IPSet.ContainsFunc.

But also IPPrefix.Contains and IPRange.Contains and IPPrefix.Overlaps and IPRange.Overlaps. But not IPSet.Overlaps if #109 goes in.

So maybe we should decide what rules we want before we decide to submit #109.

/cc @danderson @josharian @mdlayher

@josharian
Copy link
Collaborator

josharian commented Dec 31, 2020

I'd love to be able to say that everything in the package is concurrency-safe. It makes it really, really nice to use, particularly for low-level types.

If that bar is unreasonable to clear, I'd vote to split that package into concurrency-safe types (probably the simplest, lowest-level types like IP, IPPrefix, IPPort) and non-concurrency-safe types, and make no guarantees whatsoever about the latter ones.

@josharian
Copy link
Collaborator

I'd like to come to a decision here. The menu of options seems to be:

  1. Declare that value types (IP, IPRange, IPPrefix) are concurrency safe. Reference types (IPSet) are not.
  2. Declare that all types are concurrency safe. Add a mutex to IPSet.
  3. Declare that no types are concurrency safe.

My 2c:

3 seems like the worst option.

Given that we can backwards-compatibly go from 1 to 2, 1 seems the lower-risk option of the two. Mutex are cheap, though, so I'm also OK with 2.

@danderson
Copy link
Member

I was assuming 1 as our default. Concurrency safety is fantastic for consumers, so we should strive for it.

I'm on the fence about 2, but as long as we don't have any callback-based functions, I think throwing a mutex on it and guaranteeing that all types are concurrency-safe LGTM.

Agree on 3, let's not do that.

danderson added a commit that referenced this issue Jan 29, 2021
Addresses the non-documentation bits of #110.

Signed-off-by: David Anderson <[email protected]>
danderson added a commit that referenced this issue Jan 29, 2021
Addresses the non-documentation bits of #110.

Signed-off-by: David Anderson <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants