[lttng-dev] [PATCH lttng-tools 12/14] Using pthread_kill instead of pthread_cancel (not a good idea but requried for now)

David Goulet dgoulet at efficios.com
Mon May 6 15:22:58 EDT 2013


Same, should be put in a compat layer.

Charles Briere:
> From: Pierre-Luc St-Charles <pierre-luc.st-charles at polymtl.ca>
> 
> Signed-off-by: Pierre-Luc St-Charles <pierre-luc.st-charles at polymtl.ca>
> ---
>  configure.ac                  | 18 ++++++++++++++++++
>  src/bin/lttng-sessiond/main.c |  8 ++++++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/configure.ac b/configure.ac
> index c405020..154b0a7 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -198,6 +198,24 @@ AS_IF([test "x$have_pthread_cndtmwt_mono" = "xyes"],
>  	AC_DEFINE_UNQUOTED([LTTNG_HAVE_PTHREAD_CNDTMWT_MONO], 1, [Has non-standard pthread_cond_timedwait_monotonic support.])
>  ])
>  
> +# Check for pthread_cancel support (which might not be present in lightweight versions of lpthread)
> +AC_CHECK_LIB([pthread], [pthread_cancel],
> +[
> +	have_pthread_cancel=yes
> +],
> +[
> +	AC_CHECK_LIB([c], [pthread_cancel],
> +	[
> +		have_pthread_cancel=yes
> +	])
> +])
> +AS_IF([test "x$have_pthread_cancel" = "xyes"],
> +[
> +	AC_DEFINE_UNQUOTED([LTTNG_HAVE_PTHREAD_CANCEL], 1, [Has standard pthread_cancel support.])
> +],
> +[
> +	AC_MSG_WARN([The targeted platform does not support pthread_cancel; defaulting to pthread_kill, but it might not be 100% safe.])
> +])
>  
>  # URCU library version needed or newer
>  liburcu_version=">= 0.7.2"
> diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c
> index d8ff4c2..73bdc0a 100644
> --- a/src/bin/lttng-sessiond/main.c
> +++ b/src/bin/lttng-sessiond/main.c
> @@ -1816,10 +1816,18 @@ static int spawn_consumer_thread(struct consumer_data *consumer_data)
>  			 */
>  			ERR("Condition timed out. The consumer thread was never ready."
>  					" Killing it");
> +#ifdef LTTNG_HAVE_PTHREAD_CANCEL
>  			ret = pthread_cancel(consumer_data->thread);
>  			if (ret < 0) {
>  				PERROR("pthread_cancel consumer thread");
>  			}
> +#else
> +			WARN("Using pthread_kill instead of pthread_cancel...");
> +			ret = pthread_kill(consumer_data->thread,SIGTERM);
> +			if (ret < 0) {
> +				PERROR("pthread_kill consumer thread");
> +			}
> +#endif
>  		} else {
>  			PERROR("pthread_cond_wait failed consumer thread");
>  		}



More information about the lttng-dev mailing list