changeset 479:b8b412a7670a

Fix segmentation fault if multithread
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Thu, 28 Dec 2017 19:51:06 +0900
parents 0223c07c3946
children 39b5df2d1c93
files src/parallel_execution/TaskManagerImpl.cbc src/parallel_execution/TimerImpl.cbc
diffstat 2 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/TaskManagerImpl.cbc	Thu Dec 28 19:08:04 2017 +0900
+++ b/src/parallel_execution/TaskManagerImpl.cbc	Thu Dec 28 19:51:06 2017 +0900
@@ -188,12 +188,21 @@
     }
 
     taskManager->loopCounter->i = 0;
-    goto next(...);
+    goto shutdownTaskManagerImpl2();
 }
 
-__code shutdownTaskManagerImpl1(struct TaskManagerImpl* taskManager) {
-    int i = taskManager->loopCounter->i;
-    pthread_join(taskManager->workers[i]->thread, NULL);
+__code shutdownTaskManagerImpl1(struct TaskManagerImpl* taskManager, __code next(...)) {
     taskManager->loopCounter->i++;
     goto shutdownTaskManagerImpl();
 }
+
+__code shutdownTaskManagerImpl2(struct TaskManagerImpl* taskManager, __code next(...)) {
+    int i = taskManager->loopCounter->i;
+    if (i < taskManager->numWorker) {
+        pthread_join(taskManager->workers[i]->thread, NULL);
+        taskManager->loopCounter->i++;
+        goto shutdownTaskManagerImpl2();
+    }
+    taskManager->loopCounter->i = 0;
+    goto next(...);
+}
--- a/src/parallel_execution/TimerImpl.cbc	Thu Dec 28 19:08:04 2017 +0900
+++ b/src/parallel_execution/TimerImpl.cbc	Thu Dec 28 19:51:06 2017 +0900
@@ -25,8 +25,6 @@
 __code endTimer(struct TimerImpl* timer, __code next(...)) {
     struct timeval tv;
     gettimeofday(&tv, NULL);
-
     printf("%0.6f\n", (tv.tv_sec+(double)tv.tv_usec*1e-6) - timer->time);
-
     goto next(...);
 }