ThreadPool::ThreadPool(size_t threads) : m_stop(false) { for (size_t i = 0; i < threads; ++i) { m_workers.push_back(std::thread(WorkerThread())); } }
// CONSTRUCTOR //------------------------------------------------------------------------------ JobQueue::JobQueue( uint32_t numWorkerThreads ) : m_NumLocalJobsActive( 0 ), m_DistributableAvailableJobs( 1024, true ), m_DistributableJobsMemoryUsage( 0 ), m_DistributedJobsRemote( 1204, true ), m_DistributedJobsLocal( 128, true ), m_DistributedJobsCancelled( 128, true ), m_CompletedJobs( 1024, true ), m_CompletedJobsFailed( 1024, true ), m_CompletedJobs2( 1024, true ), m_CompletedJobsFailed2( 1024, true ), m_Workers( numWorkerThreads, false ) { WorkerThread::InitTmpDir(); for ( uint32_t i=0; i<numWorkerThreads; ++i ) { // identify each worker with an id starting from 1 // (the "main" thread is considered 0) uint32_t threadIndex = ( i + 1 ); WorkerThread * wt = FNEW( WorkerThread( threadIndex ) ); wt->Init(); m_Workers.Append( wt ); } }
void NetworkService::run() { m_impl->service->reset(); m_impl->connectionsManager->enable(); // Inizializza il timer m_impl->timer = createAsioObject<boost::asio::deadline_timer>(*getService()); startTimer(); OS_ASSERT(m_impl->workerThreads.empty()); uint32 workerThreadsCount = getWorkerThreadsCount(); for(uint32 i = 0; i < workerThreadsCount; i++) { shared_ptr<WorkerThread> thread(OS_NEW WorkerThread(boost::bind(&NetworkService::runService, this))); // Assegna ai sotto threads la stessa priorità del thread principale thread->setPriority(getPriority()); // Accoda e avvia il sottothread m_impl->workerThreads.add(thread, true); } // Avvia il servizio runService(); // Attende la chiusura di tutti i threads m_impl->workerThreads.join(); m_impl->workerThreads.clear(); }
bool threading::ThreadPool::initialize() { for (auto& workerThread: workerThreads) { workerThread.join(); } for (unsigned int i = 0; i < settings.numThreads; ++i) { workerThreads.push_back(std::thread(WorkerThread(*this))); } return true; }
// Render the scene. void D3D12Multithreading::OnRender() { BeginFrame(); #if SINGLETHREADED for (int i = 0; i < NumContexts; i++) { WorkerThread(reinterpret_cast<LPVOID>(i)); } MidFrame(); EndFrame(); m_commandQueue->ExecuteCommandLists(_countof(m_pCurrentFrameResource->m_batchSubmit), m_pCurrentFrameResource->m_batchSubmit); #else for (int i = 0; i < NumContexts; i++) { SetEvent(m_workerBeginRenderFrame[i]); // Tell each worker to start drawing. } MidFrame(); EndFrame(); WaitForMultipleObjects(NumContexts, m_workerFinishShadowPass, TRUE, INFINITE); // You can execute command lists on any thread. Depending on the work // load, apps can choose between using ExecuteCommandLists on one thread // vs ExecuteCommandList from multiple threads. m_commandQueue->ExecuteCommandLists(NumContexts + 2, m_pCurrentFrameResource->m_batchSubmit); // Submit PRE, MID and shadows. WaitForMultipleObjects(NumContexts, m_workerFinishedRenderFrame, TRUE, INFINITE); // Submit remaining command lists. m_commandQueue->ExecuteCommandLists(_countof(m_pCurrentFrameResource->m_batchSubmit) - NumContexts - 2, m_pCurrentFrameResource->m_batchSubmit + NumContexts + 2); #endif m_cpuTimer.Tick(NULL); if (m_titleCount == TitleThrottle) { WCHAR cpu[64]; swprintf_s(cpu, L"%.4f CPU", m_cpuTime / m_titleCount); SetCustomWindowText(cpu); m_titleCount = 0; m_cpuTime = 0; } else { m_titleCount++; m_cpuTime += m_cpuTimer.GetElapsedSeconds() * 1000; m_cpuTimer.ResetElapsedTime(); } // Present and update the frame index for the next frame. PIXBeginEvent(m_commandQueue.Get(), 0, L"Presenting to screen"); ThrowIfFailed(m_swapChain->Present(0, 0)); PIXEndEvent(m_commandQueue.Get()); m_frameIndex = m_swapChain->GetCurrentBackBufferIndex(); // Signal and increment the fence value. m_pCurrentFrameResource->m_fenceValue = m_fenceValue; ThrowIfFailed(m_commandQueue->Signal(m_fence.Get(), m_fenceValue)); m_fenceValue++; }
void* BXBGProcess::WorkerPThread( void* pParam ) { WorkerThread( pParam ); return (void*)0; }