[PATCH v7 1/6] lib: add function to get the number of threads matching a search