void Win32ThreadSupport::startThreads(const Win32ThreadConstructionInfo& threadConstructionInfo) { m_activeSpuStatus.resize(threadConstructionInfo.m_numThreads); m_completeHandles.resize(threadConstructionInfo.m_numThreads); m_maxNumTasks = threadConstructionInfo.m_numThreads; for (int i=0;i<threadConstructionInfo.m_numThreads;i++) { printf("starting thread %d\n",i); btSpuStatus& spuStatus = m_activeSpuStatus[i]; LPSECURITY_ATTRIBUTES lpThreadAttributes=NULL; SIZE_T dwStackSize=threadConstructionInfo.m_threadStackSize; LPTHREAD_START_ROUTINE lpStartAddress=&Thread_no_1; LPVOID lpParameter=&spuStatus; DWORD dwCreationFlags=0; LPDWORD lpThreadId=0; spuStatus.m_userPtr=0; sprintf(spuStatus.m_eventStartHandleName,"eventStart%s%d",threadConstructionInfo.m_uniqueName,i); spuStatus.m_eventStartHandle = CreateEvent(0,false,false,spuStatus.m_eventStartHandleName); sprintf(spuStatus.m_eventCompletetHandleName,"eventComplete%s%d",threadConstructionInfo.m_uniqueName,i); spuStatus.m_eventCompletetHandle = CreateEvent(0,false,false,spuStatus.m_eventCompletetHandleName); m_completeHandles[i] = spuStatus.m_eventCompletetHandle; HANDLE handle = CreateThread(lpThreadAttributes,dwStackSize,lpStartAddress,lpParameter, dwCreationFlags,lpThreadId); SetThreadPriority(handle,THREAD_PRIORITY_HIGHEST); //SetThreadPriority(handle,THREAD_PRIORITY_TIME_CRITICAL); SetThreadAffinityMask(handle, 1<<i); spuStatus.m_taskId = i; spuStatus.m_commandId = 0; spuStatus.m_status = 0; spuStatus.m_threadHandle = handle; spuStatus.m_lsMemory = threadConstructionInfo.m_lsMemoryFunc(); spuStatus.m_userThreadFunc = threadConstructionInfo.m_userThreadFunc; printf("started thread %d with threadHandle %p\n",i,handle); } }
void b3Win32ThreadSupport::startThreads(const Win32ThreadConstructionInfo& threadConstructionInfo) { static int uniqueId = 0; uniqueId++; m_activeThreadStatus.resize(threadConstructionInfo.m_numThreads); m_completeHandles.resize(threadConstructionInfo.m_numThreads); m_maxNumTasks = threadConstructionInfo.m_numThreads; for (int i=0;i<threadConstructionInfo.m_numThreads;i++) { printf("starting thread %d\n",i); b3ThreadStatus& threadStatus = m_activeThreadStatus[i]; LPSECURITY_ATTRIBUTES lpThreadAttributes=NULL; SIZE_T dwStackSize=threadConstructionInfo.m_threadStackSize; LPTHREAD_START_ROUTINE lpStartAddress=&Thread_no_1; LPVOID lpParameter=&threadStatus; DWORD dwCreationFlags=0; LPDWORD lpThreadId=0; threadStatus.m_userPtr=0; sprintf(threadStatus.m_eventStartHandleName,"es%.8s%d%d",threadConstructionInfo.m_uniqueName,uniqueId,i); threadStatus.m_eventStartHandle = CreateEventA (0,false,false,threadStatus.m_eventStartHandleName); sprintf(threadStatus.m_eventCompletetHandleName,"ec%.8s%d%d",threadConstructionInfo.m_uniqueName,uniqueId,i); threadStatus.m_eventCompletetHandle = CreateEventA (0,false,false,threadStatus.m_eventCompletetHandleName); m_completeHandles[i] = threadStatus.m_eventCompletetHandle; HANDLE handle = CreateThread(lpThreadAttributes,dwStackSize,lpStartAddress,lpParameter, dwCreationFlags,lpThreadId); switch(threadConstructionInfo.m_priority) { case 0: { SetThreadPriority(handle,THREAD_PRIORITY_HIGHEST); break; } case 1: { SetThreadPriority(handle,THREAD_PRIORITY_TIME_CRITICAL); break; } case 2: { SetThreadPriority(handle,THREAD_PRIORITY_BELOW_NORMAL); break; } default: { } } DWORD mask = 1; mask = 1<<mask; SetThreadAffinityMask(handle, mask); threadStatus.m_taskId = i; threadStatus.m_commandId = 0; threadStatus.m_status = 0; threadStatus.m_threadHandle = handle; threadStatus.m_lsMemory = threadConstructionInfo.m_lsMemoryFunc(); threadStatus.m_userThreadFunc = threadConstructionInfo.m_userThreadFunc; printf("started %s thread %d with threadHandle %p\n",threadConstructionInfo.m_uniqueName,i,handle); } }