user_agent
user_agent copied to clipboard
Concurrency support?
Does this support concurrent calls? It doesn't look like it, given that New()
returns a pointer without a mutex
to protect concurrent reads or writes.
This is important in the case of memory use on a web server, for example. I would rather initialize it once and call it repeatedly as opposed to re-initializing it on every client connection, which would end up needlessly adding and removing from the heap as well as increase the amount the garbage collector has to work.
Adding concurrency would simply be a matter of adding a sync.RWMutex
field to the UserAgent
struct, and calling the UserAgent.RWMutex
field's RLock()
/RUnlock()
or Lock()
/Unlock()
methods in every library method that reads or writes to the struct, respectively.