Feature: Add thread-safety
Closed this issue · 3 comments
See: #5 (comment)
@DrTall I'm yet to see a use-case where a concurrent backoff timer is required. Do you have a particular case in mind?
I'm making use of the new ForAttempt
method by sharing a single *Backoff
object across many objects in multiple threads. In this way, the backoff settings (which are all identical) are not duplicated. But ForAttempt
isn't thread safe today, which seems to defeat the purpose.
To be clear, I agree that the Backoff
class as a whole is fine not being threadsafe. A user could just put a mutex around it if need be.
This triggers the race detector, but is in fact safe. The convenience of the current way of doing things is great. I would suggest you just set all the fields in your Backoff
struct as a work-around. Either way ForAttempt
should be documented as not being safe for concurrent access unless you set all the fields.
That's probably the best compromise considering this is not the primary use case. I'll send a pull request for the comments.