浏览代码

Fix a bug that caused starpu_shutdown to crash when running drivers in the application.

Cyril Roelandt 13 年之前
父节点
当前提交
5b767e5880
共有 2 个文件被更改,包括 17 次插入0 次删除
  1. 16 0
      src/core/workers.c
  2. 1 0
      src/core/workers.h

+ 16 - 0
src/core/workers.c

@@ -273,6 +273,7 @@ static void _starpu_launch_drivers(struct _starpu_machine_config *config)
 		workerarg->worker_size = 1;
 		workerarg->combined_workerid = workerarg->workerid;
 		workerarg->current_rank = 0;
+		workerarg->run_by_starpu = 1;
 
 		/* if some codelet's termination cannot be handled directly :
 		 * for instance in the Gordon driver, Gordon tasks' callbacks
@@ -303,6 +304,10 @@ static void _starpu_launch_drivers(struct _starpu_machine_config *config)
 					pthread_create(&workerarg->worker_thread,
 							NULL, _starpu_cpu_worker, workerarg);
 				}
+				else
+				{
+					workerarg->run_by_starpu = 0;
+				}
 				cpu++;
 				break;
 #endif
@@ -316,6 +321,10 @@ static void _starpu_launch_drivers(struct _starpu_machine_config *config)
 					pthread_create(&workerarg->worker_thread,
 						       NULL, _starpu_cuda_worker, workerarg);
 				}
+				else
+				{
+					workerarg->run_by_starpu = 0;
+				}
 				cuda++;
 				break;
 #endif
@@ -323,7 +332,10 @@ static void _starpu_launch_drivers(struct _starpu_machine_config *config)
 			case STARPU_OPENCL_WORKER:
 				starpu_opencl_get_device(workerarg->devid, &driver.id.opencl_id);
 				if (!_starpu_may_launch_driver(config->conf, &driver))
+				{
+					workerarg->run_by_starpu = 0;
 					break;
+				}
 				workerarg->set = NULL;
 				workerarg->worker_is_initialized = 0;
 				pthread_create(&workerarg->worker_thread,
@@ -661,6 +673,9 @@ static void _starpu_terminate_workers(struct _starpu_machine_config *config)
 		}
 		else
 		{
+			if (!worker->run_by_starpu)
+				goto out;
+
 			if (!pthread_equal(pthread_self(), worker->worker_thread))
 			{
 				status = pthread_join(worker->worker_thread, NULL);
@@ -673,6 +688,7 @@ static void _starpu_terminate_workers(struct _starpu_machine_config *config)
 			}
 		}
 
+out:
 		STARPU_ASSERT(starpu_task_list_empty(&worker->local_tasks));
 		_starpu_job_list_delete(worker->terminated_jobs);
 	}

+ 1 - 0
src/core/workers.h

@@ -80,6 +80,7 @@ struct _starpu_worker
 	enum _starpu_worker_status status; /* what is the worker doing now ? (eg. CALLBACK) */
 	char name[48];
 	char short_name[10];
+	unsigned run_by_starpu; /* Is this run by StarPU or directly by the application ? */
 
 #ifdef __GLIBC__
 	cpu_set_t initial_cpu_set;