That is the simplest and most conservative way go about it, but ultimately it depends on what you need out of your concurrency semantics.
If you're willing to settle for a linearizable execution, you can gain some performance improvements by only checking the lock for write operations. So long as two write operations do not pass each other in the tree, they will be linearizable based on which write passed the root node first. Read operations can pass one another (and other write operations) freely. We can always pick a linearization point for them with respect to the rest of the concurrent write operations in the tree. You will also need to do hand-over-hand locking on your way down the tree to ensure no two writes can overtake one another. An approach like this can yield significant performance gains and you can formally show that the results you get are correct with regard to some actual state the tree could be in depending on when you consider each concurrent write to "complete". On Tue, Jan 5, 2021, 5:53 PM joseph.p...@gmail.com < joseph.p.mcguc...@gmail.com> wrote: > Is there a simple tree library that is thread safe? > > If I have to write one for myself, do I have to set locks on nodes as I > walk the tree to > prevent another thread from changing nodes that are 'above' me? > > -- > 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/6597198c-c439-4a1e-bff2-a2176204b272n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/6597198c-c439-4a1e-bff2-a2176204b272n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CALJzkY-RSMPbObc-Dxhw985O9v_raMhGNwGcy03%3DKuWRTHeRmg%40mail.gmail.com.