From ebea9b523792a940e208c59236ecf10c197b6dc6 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 14 Nov 2021 13:34:20 +0000 Subject: [PATCH] Submitted by Ivan Frederiks: patch #9079: Fix ftdi_syncbb teardown Fix teardown sequence between reader thread and libusb. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1473 81a1dc3b-b13d-400b-aceb-764788c761c2 --- ft245r.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/ft245r.c b/ft245r.c index ca78a73d..b155e82e 100644 --- a/ft245r.c +++ b/ft245r.c @@ -173,16 +173,22 @@ static void add_to_buf (unsigned char c) { } static void *reader (void *arg) { - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,NULL); + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,NULL); struct ftdi_context *handle = (struct ftdi_context *)(arg); unsigned char buf[0x1000]; int br, i; while (1) { + /* 'old_cancel_state' added for portability reasons, + * see pthread_setcancelstate() manual */ + int old_cancel_state; pthread_testcancel(); + /* isolate libftdi and libusb from cancellation requests to prevent unhandled behavior */ + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancel_state); br = ftdi_read_data (handle, buf, sizeof(buf)); for (i=0; i= 100) { - avrdude_message(MSG_INFO, "Too many retry to close reader thread\n"); - } - - pthread_join(readerthread, NULL); ftdi_deinit (handle); free(handle); handle = NULL;