-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
container/list should state that it is not thread-safe #25105
Comments
This is true of most of the standard library. Even built-in maps are not thread safe. I'm not sure we want to pepper every API with such a warning. |
I agree with @randall77. Per Effective Go:
Package-level functions are generally safe for concurrent use, but methods on individual values are not. We document the exceptions to that rule, not the cases that comply with it. |
OTOH, we certainly should mention the race detector in Effective Go. It seems we currently do not (#25107). |
Fair enough: I do make use of channels etc. but in this case I'm synchronising a semi-synchronous stream with a synchronous one, filling in any gaps by re-inserting nearby data, and so a pair of lists with a timed function in the middle seems like the obvious answer. Just need to remember that, despite its modernity, linked lists in Golang are as "exciting" as ever. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go1.6.2
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?linux/amd64
What did you do?
Accessed a
container/list
from two differentgo func()
routines.What were you tripped-up by
A panic occurred in
list.PushBack()
due to a nil pointer reference. This was because the other (timed)go func()
routine was iterating through the list, processing entries, and then callinglist.Remove()
on the processed items. It seems as though the threading in Golang is so good that the timedgo func()
is acting upon an item while it is in the middle of being added to the list withlist.PushBack()
.What would you like to happen as a result?
It would be a good idea to add to the top of the
container/list
documentation page that it is NOT thread-safe, just so that no-one else falls over this. It took a few million attempts for me to hit it; an hour or two with loops iterating every 20 ms: it might be a very intermittent fatal bug for others, so worth a warning.The text was updated successfully, but these errors were encountered: