/*!\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/xNewDelete.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=xNew(num_threads); handles=xNew(num_threads); for(i=0;i(threads); xDelete(handles); #else pthread_handle handle; handle.gate=gate; handle.id=0; handle.num=1; function((void*)&handle); #endif }