Firstly, forgive me if this is a stupid question. I would like to create a generic synchronised list (like in Java) for reuse in my Go projects. I found the source of Go's linked list and I was wondering would it be sufficient to simply add mutex locks to the list manipulation functions?
If you're going to make a concurrent-safe container, you need to protect all access to the data, not just writes. Inspecting an element, or even calling Len()
without synchronizing the read could return invalid or corrupt data.
It's probably easier to protect the entire data structure with a mutex, rather than implement your own concurrent linked list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With