On Wednesday, 6 July 2022 at 11:33:29 UTC+1 ren...@ix.netcom.com wrote: > As I said, make the mutating op simply record the desired op on a queue > and process the serially on another thread. You are essentially > implementing transactions. >
But how do you protect tree *readers* from having mutations take place under their feet? You could serialize all reads as well, and copy the results. But I don't think that's what the OP was intending. You could have aRWMutex, but then it's up to the API caller to obtain that mutex *for as long as necessary* (e.g. while traversing part of the tree). Depending on the use case, a "functional" approach might be worth considering: - nodes are strictly immutable - if you need to modify a node, create a new node instead - recursively repeat for every other node that holds a pointer to this node. - atomically update the "tree root" pointer Then each reader sees a snapshot of the tree at a point in time, and garbage collection should take care of the rest. -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/888413c1-d4ff-4752-a607-2a3f2196e1dfn%40googlegroups.com.