[dpdk-dev] [PATCH v2 1/2] eal: add API that sleeps while waiting for threads

Ananyev, Konstantin konstantin.ananyev at intel.com
Tue Oct 16 11:05:16 CEST 2018


> 
> +/*
> + * Wait until a lcore finished its job by pthread condition.
> + */
> +int
> +rte_eal_wait_lcore_sleep(unsigned slave_id)
> +{
> +	if (lcore_config[slave_id].state == WAIT)
> +		return 0;
> +
> +	pthread_mutex_lock(&rte_eal_thread_mutex[slave_id]);
> +	while (lcore_config[slave_id].state != WAIT &&
> +	       lcore_config[slave_id].state != FINISHED)
> +		pthread_cond_wait(&rte_eal_thread_cond[slave_id],
> +				&rte_eal_thread_mutex[slave_id]);
> +	pthread_mutex_unlock(&rte_eal_thread_mutex[slave_id]);
> +
> +	/* we are in finished state, go to wait state */
> +	lcore_config[slave_id].state = WAIT;
> +	return lcore_config[slave_id].ret;
> +}
> +

Actually, another question - could that 2 or more threads wait for the same core simultaneously?
If yes, then 2-nd thread in that function might stuck forever.
In that case it is better to use cond_timed_wait() here and cond_broadcast() above.
Konstantin


More information about the dev mailing list