Adjust code code structure

Add a function to get thread index within thread lifecycle