/* Return the first free entry index in the threads table  */
static int ttable_get_empty_slot(void)
/* Return the first free entry index in the threads table  */
static int ttable_get_empty_slot(void)
{
	for (int i = 0; i < threads_table_size; i++) {
		if ((threads_table[i].state == NOTUSED)
			|| (PC_REUSE_ABORTED_ENTRIES
			&& (threads_table[i].state == ABORTED))) {
			return i;
		}
	}
	threads_table = realloc(threads_table,
				(threads_table_size + PC_ALLOC_CHUNK_SIZE)
				* sizeof(struct threads_table_el));
	if (threads_table == NULL) {
		posix_print_error_and_exit(NO_MEM_ERR);
	}
	(void)memset(&threads_table[threads_table_size], 0,
		     PC_ALLOC_CHUNK_SIZE * sizeof(struct threads_table_el));
	threads_table_size += PC_ALLOC_CHUNK_SIZE;
	return threads_table_size - PC_ALLOC_CHUNK_SIZE;
}