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;