code: func (tp *DocumentsWriterPerThreadPool) newThreadState() (ts *ThreadState) {
  	tp.Lock()
  	defer tp.Unlock()
  
  	// Create a new empty thread state if possible
  	if len(tp.threadStates) < cap(tp.threadStates) {
  		ts = newThreadState(len(tp.threadStates))
  		tp.threadStates = append(tp.threadStates, ts)
  		tp.lockedList.PushBack(ts.id)
  	}
  	return
  }
docs: /*
  Returns a new ThreadState iff any new state is available otherwise
  nil.
  
  NOTE: the returned ThreadState is already locked iff non-nil.
  */