I hope patches are welcome.

The appended patch solves the problem, that the whole application
terminates on the call of canClose.

Instead of using pthread_kill to send a SIGTERM signal to the thread you
can use pthread_cancel to interrupt
the execution of the thread. This require some more initialisation in
the thread function. You have to enable the
cancel ability and make sure that the thread can be canceled an every
point of the execution.

Kind Regards,

Index: CanFestival-3/drivers/timers_unix/timers_unix.c
===================================================================
--- CanFestival-3.orig/drivers/timers_unix/timers_unix.c        2015-07-23 
09:05:30.227330057 +0200
+++ CanFestival-3/drivers/timers_unix/timers_unix.c     2015-07-23 
09:42:54.758865181 +0200
@@ -1,12 +1,12 @@
 #include <stdlib.h>
 
 #include <sys/time.h>
-#include <pthread.h> 
+#include <pthread.h>
 #include <signal.h>
 #include <time.h>
 
-#include "applicfg.h"
-#include "timer.h"
+#include <applicfg.h>
+#include <timer.h>
 
 static pthread_mutex_t CanFestival_mutex = PTHREAD_MUTEX_INITIALIZER;
 
@@ -104,6 +104,20 @@
        //  if(signal(SIGTERM, canReceiveLoop_signal) == SIG_ERR) {
        //              perror("signal()");
        //}
+
+    // Set the cancelation state for immediatly cancel the task
+    int ret;
+
+    ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+
+    if (ret != 0)
+        perror("Can't enable the cancelation of the receiving task");
+
+    ret = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+
+    if (ret != 0)
+        perror("Can't set the asynchronous cancel typ");
+
     unixtimer_ReceiveLoop_task_proc((CAN_PORT)port);
 
     return NULL;
@@ -119,8 +133,8 @@
 
 void WaitReceiveTaskEnd(TASK_HANDLE *Thread)
 {
-       if(pthread_kill(*Thread, SIGTERM)) {
-               perror("pthread_kill()");
+       if(pthread_cancel(*Thread)) {
+               perror("pthread_cancel()");
        }
 
        if(pthread_join(*Thread, NULL)) {
------------------------------------------------------------------------------
_______________________________________________
Canfestival-devel mailing list
Canfestival-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/canfestival-devel

Reply via email to