Have a public Set() that does the lock and then calls a private internal function, which assumes it's already running under the lock. https://go.dev/play/p/M1XuC8bxCxL
On Tuesday, 5 July 2022 at 13:32:26 UTC+1 atd...@gmail.com wrote: > Hi, > > I have a tree datastructure where mutating some nodes *may *trigger a > mutation on some other tree nodes. > > This tree should be accessible by multiple goroutines but mutated by only > one at a time. > > As such, I wanted to have a global lock on the tree such that mutatiing > node methods should acquire this lock beforehand. > > But it seems to require for the mutex to be reentrant? > > I have tried to create a very simplified*** model to illustrate > https://go.dev/play/p/v37cbYQ1jSY > > (***) I know people might want to suggest for the Set method to use a > lockless variant when iterating over the linked nodes but in the real code, > it iterates over user created callbacks instead and I don't think I can > expect callbacks writers to juggle between the two kind of methods to avoid > deadlocks. > > Any suggestion? > > -- 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/42e71458-8d9c-4b80-9c46-d6d0a96b71abn%40googlegroups.com.