/*!\file: LaunchThread.cpp * \brief launch thread in a generic way, covering single and multi-threaded cases * This routine attempts to simplify management of multi-threading. When multi-threadeing * is not requested (serial run), LaunchThread will just call the function (provided in argument * list), nothing fancy there. If multi-threading is requested, LaunchThread will launch the * function on multiple threads (num_threads of them), and provide these functions with the * local data they need (folded in the "gate" structure) + the thread id + the number of threads * All this info is collected in the pthread_handle structure. */ #ifdef HAVE_CONFIG_H #include #else #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" #endif #ifdef _MULTITHREADING_ #include #endif #include "./issm_threads.h" #include "../Alloc/alloc.h" #include "../Exceptions/exceptions.h" #include "../../include/include.h" void LaunchThread(void* function(void*), void* gate,int num_threads){ #ifdef _MULTITHREADING_ int i; int* status=NULL; pthread_t* threads=NULL; pthread_handle* handles=NULL; /*dynamically allocate: */ threads=(pthread_t*)xmalloc(num_threads*sizeof(pthread_t)); handles=(pthread_handle*)xmalloc(num_threads*sizeof(pthread_handle)); for(i=0;i