1 #include "mapThreadsSpawn.h"
2 #include "ThreadControl.h"
3 #include "GlobalVariables.h"
4 #include "ErrorWarning.h"
5
mapThreadsSpawn(Parameters & P,ReadAlignChunk ** RAchunk)6 void mapThreadsSpawn (Parameters &P, ReadAlignChunk** RAchunk) {
7 for (int ithread=1;ithread<P.runThreadN;ithread++) {//spawn threads
8 int threadStatus=pthread_create(&g_threadChunks.threadArray[ithread], NULL, &g_threadChunks.threadRAprocessChunks, (void *) RAchunk[ithread]);
9 if (threadStatus>0) {//something went wrong with one of threads
10 ostringstream errOut;
11 errOut << "EXITING because of FATAL ERROR: phtread error while creating thread # " << ithread <<", error code: "<<threadStatus ;
12 exitWithError(errOut.str(),std::cerr, P.inOut->logMain, 1, P);
13 };
14 pthread_mutex_lock(&g_threadChunks.mutexLogMain);
15 P.inOut->logMain << "Created thread # " <<ithread <<"\n"<<flush;
16 pthread_mutex_unlock(&g_threadChunks.mutexLogMain);
17 };
18
19 RAchunk[0]->processChunks(); //start main thread
20
21 for (int ithread=1;ithread<P.runThreadN;ithread++) {//wait for all threads to complete
22 int threadStatus = pthread_join(g_threadChunks.threadArray[ithread], NULL);
23 if (threadStatus>0) {//something went wrong with one of threads
24 ostringstream errOut;
25 errOut << "EXITING because of FATAL ERROR: phtread error while joining thread # " << ithread <<", error code: "<<threadStatus ;
26 exitWithError(errOut.str(),std::cerr, P.inOut->logMain, 1, P);
27 };
28 pthread_mutex_lock(&g_threadChunks.mutexLogMain);
29 P.inOut->logMain << "Joined thread # " <<ithread <<"\n"<<flush;
30 pthread_mutex_unlock(&g_threadChunks.mutexLogMain);
31 };
32 };
33
34