I want to use the same regular expression concurrently in several
goroutines.
But the regexp package's documentation does not specify whether
*regexp.Regexp values are thread safe.
So, I must assume that they are not thread safe (i.e., calling
*regexp.Regexp methods might change the pointed to value's internal
state).
I think it would be helpful if the documentation specified which types
that are accessed through pointers are thread safe and which aren't.
(Unless none of them are of course.)
For now I'll give each goroutine the string from which the regular
expression is compiled and have them create their own.
Regards.
--
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
C++, Python, Qt, PyQt - training and consultancy
"Advanced Qt Programming" - ISBN 0321635906
http://www.qtrac.eu/aqpbook.html
Analysis of types for thread-safety is a non-trivial enterprise, even
for their original authors. Expecting all users of a language to
determine for themselves if a given context struct is threadsafe by
reading the implementation of the package is probably not reasonable.
A simple rule would be sufficient: Go standard library packages are
not threadsafe, unless otherwise explicitly noted. Is that accurate?
Indeed. Plus, the question is not whether it is thread safe or not
today, but whether the authors promise to maintain safety. Code
shouldn't be assumed to be thread safe unless the guarantee is
explicitly stated.
> A simple rule would be sufficient: Go standard library packages are
> not threadsafe, unless otherwise explicitly noted. Is that accurate?
Yes, and that's valid for pretty much any software.
--
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/blog
http://niemeyer.net/twitter
It should be safe. Execution state is kept separate from the *Regexp.
-rob
I feel strongly that the public API and its documentation are all that
one should rely upon. I'm happy to look into the source code to learn
how things are done (and godoc makes this particularly easy which is v.
nice), but never as a means of "optimizing" on the basis of a particular
implementation that might change at any time:-)
--
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
C++, Python, Qt, PyQt - training and consultancy
"Programming in Go" - ISBN 0321774639
http://www.qtrac.eu/gobook.html
I promise it's safe.
We'll fix the docs.
That's silly. I'm telling you it's safe.
> I feel strongly that the public API and its documentation are all that
> one should rely upon. I'm happy to look into the source code to learn
> how things are done (and godoc makes this particularly easy which is v.
> nice), but never as a means of "optimizing" on the basis of a particular
> implementation that might change at any time:-)
Docs will be fixed.
-rob
OK, a promise is good: I'll create one regex and share it:-)
> We'll fix the docs.
Thanks!
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.