7 #ifndef __thread_Gang_h__ 8 #define __thread_Gang_h__ 20 template<
typename WORKER,
typename T>
29 { Counted::setName(
"Gang"); }
40 U32 a_threads=0,
String a_stage=
"")
47 a_threads=Thread::hardwareConcurrency();
54 m_pGroup=
new Thread::Group();
55 m_ppWorker=
new WORKER*[a_threads];
56 m_ppThread=
new Thread*[a_threads];
58 for(U32 m=0;m<a_threads;m++)
60 m_ppWorker[m]=
new WORKER(spJobQueue,m,a_stage);
61 m_ppWorker[m]->setObject(a_spObject);
65 for(U32 m=0;m<a_threads;m++)
74 m_ppThread[m]=m_pGroup->createThread(
78 feX(e_cannotCreate,
"Gang::start",
79 "failed to create thread");
83 catch (std::exception& e)
88 pException->getResult()==e_cannotCreate)
90 #if FE_CODEGEN<=FE_DEBUG 92 " failed to create thread\n");
99 " failed to create thread " 100 " worker %d/%d try %d/%d" 102 m,a_threads,tries,maxTries,e.what());
103 if(++tries>=maxTries)
106 " giving up creating thread\n");
113 " interrupt %d/%d\n",n,m);
114 m_ppThread[n]->interrupt();
118 feLog(
"Gang::start cleaning up\n");
120 feLog(
"Gang::start done\n");
125 feLog(
"Gang::start retrying\n");
130 feLog(
"Gang::start retry succeeded\n");
154 void discardWorkers(
void)
156 for(U32 m=0;m<JobQueue<T>::m_workers;m++)
165 delete m_ppThread[m];
169 delete m_ppWorker[m];
185 Thread::Group* m_pGroup;
193 #endif // __thread_Gang_h__ Group of Worker threads.
Definition: Gang.h:21
kernel
Definition: namespace.dox:3
Generic exception carrying a fe::String payload.
Definition: Exception.h:34
Automatically reference-counted string container.
Definition: String.h:128
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
Queue of tasks.
Definition: JobQueue.h:29