I'm trying to implement an array-based lock-free binary search tree. In order to make it work concurrently, I should lock a range of array in method. How can I achieve it?
public int getIndex(int data){
        int index = 1;
        while(index<this.capacity && this.array[index] != 0){
            if(data < this.array[index])
                index = index *2;
            else if (data> this.array[index])
                index = index * 2 + 1;
            else
                break;
        }
        if(index >= this.capacity)
            return -1;
        else
            return index;
    }
public void insert(int data){
        int index = this.getIndex(data);
        if (index == -1) {
            this.reallocate();
            index = this.getIndex(data);
            this.array[index] = data;
        }
        else {
            if (this.array[index] == 0)
                this.array[index] = data;
        }
    }
I'm getting where to put data in getIndex method and insert it. So, in getIndex i should lock part of array that i'm iterating.
 
     
     
    