March 2019
Intermediate to advanced
336 pages
9h 9m
English
Operations that are performed on synchronized TreeSets are synchronized across multiple calls that access the elements of TreeSets. Synchronization in TreeSets is achieved using a sync.RWMutex lock. The lock method on the tree's lock instance is invoked, and the unlock method is deferred before the tree nodes are inserted, deleted, or updated:
// InsertElement methodfunc (tree *BinarySearchTree) InsertElement(key int, value int) { tree.lock.Lock() defer tree.lock.Unlock() var treeNode *TreeNode treeNode = &TreeNode{key, value, nil, nil} if tree.rootNode == nil { tree.rootNode = treeNode } else { insertTreeNode(tree.rootNode, treeNode) }}
Read now
Unlock full access