Re: [PATCH 3/4] run-command: allow aborting async code prematurely

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 31, 2011 at 8:44 PM, Jeff King <peff@xxxxxxxx> wrote:
> We provide only two abstract promitives for async code:
> start and finish. Where "finish" means to wait until the
> async code tells us it is done. However, it may also be
> useful for us to to tell the async code to abort right away,
> because whatever it was doing is no longer useful.
>
> For a separate process, we just kill() it. For Windows, we
> need to do whatever the equivalent to pthread_cancel is.
>
> Signed-off-by: Jeff King <peff@xxxxxxxx>
> ---
>  run-command.c |   10 ++++++++++
>  run-command.h |    1 +
>  2 files changed, 11 insertions(+), 0 deletions(-)
>
> diff --git a/run-command.c b/run-command.c
> index 258c880..f179d2a 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -439,6 +439,16 @@ int finish_async(struct async *async)
>        return ret;
>  }
>
> +void abort_async(struct async *async)
> +{
> +#ifndef WIN32
> +       kill(async->pid, 15);

This doesn't compile unless NO_PTHREADS is set, no?

> +#else
> +       /* no clue */
> +#endif
> +       finish_async(async);
> +}
> +

This should probably be

void abort_async(struct async *async)
{
#ifdef NO_PTHREADS
	kill(async->pid, 15);
#else
	pthread_cancel(async->tid)
#endif
	finish_async(async);
}

... and then us Windows-guys must implement something like pthread_cancel().

Or maybe not. Can pthread reliably cancel a thread while making sure
that thread isn't holding a mutex (like some thread-safe malloc
implementations do)? If not, I'm not entirely sure we can even reach
this goal.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]