void btThreadPool::resizeThreads(int numThreads) { if (numThreads == m_numThreads) return; btAssert(numThreads > 0); // Don't allow the user to resize the thread count to below 0 or 0 - use stopThreads instead btAssert(!m_bRunningTasks); // Don't modify this if we're running tasks!!! if (numThreads < m_numThreads) { for (int i = m_numThreads - 1; i >= numThreads; i--) { endThread(m_pThreadInfo[i]); btFree(m_pThreadInfo[i]); m_pThreadInfo.pop_back(); } } else { // More threads! m_pThreadInfo.resize(numThreads); // FYI: This doesn't actually change the thread info location since threads still need it! for (int i = m_numThreads; i < numThreads; i++) { m_pThreadInfo[i] = (btThreadPoolInfo *)btAlloc(sizeof(btThreadPoolInfo)); btThreadPoolInfo *pInfo = m_pThreadInfo[i]; pInfo->threadId = i; beginThread(pInfo); } } m_numThreads = numThreads; }
void main1() { time_t timet; unsigned int startTime = time(&timet); char* path = "E:\\BaiduYunDownload\\2014传智播客C++第三期更新完毕\\0726\\code\\dangdangwang.txt"; char* pathGet = "C:\\Users\\HDZhang\\Desktop\\dangdangwang.txt"; FILE* pFile = fopen(path, "r"); FILE* pGetFile = fopen(pathGet, "w"); if (pFile && pGetFile) { printf("打开文件成功!\n"); fseek(pFile, 0, SEEK_END); int size = ftell(pFile); printf("大小: \t%d:B\t%.2f:K\t%.2f:M\t%.2f:G\n", size, size / 1024.0, size / 1024.0 / 1024.0, size / 1024.0 / 1024.0 / 1024.0); rewind(pFile); int count = 0; while (!feof(pFile)) { char buff[275] = { 0 }; fgets(buff, 275, pFile); ppStr[count] = (char*)malloc(sizeof(char)*(strlen(buff) + 1)); strcpy(ppStr[count++], buff); } printf("\n载入完成! 总共: %d条\n", count); printf("用时: %d秒\n", (time(&timet) - startTime)); } else { printf("打开文件失败!"); } fclose(pFile); fclose(pGetFile); char key[64] = { 0 }; int threadNum = 1; printf("\n请输入关键字:"); scanf("%s", key); printf("\n线程数:"); scanf("%d", &threadNum); while (strcmp(key, "-1") != 0) { //DATA_NUM beginThread(threadNum, key); printf("\n请输入关键字:"); scanf("%s", key); printf("\n线程数:"); scanf("%d", &threadNum); } system("pause"); }
void initMusicLibrary() { indexReady = 0; // check for a pre-built index if(g_file_test("/home/joleary/Projects/zenzibar/mLib.xml",G_FILE_TEST_EXISTS)) { // load and parse the index // set the index to ready } else { beginThread(); } }
//SERVER SETUP void TalkyBase::setup(int localPort) { if (nodeType != 0) { throw("Already initialised as node type " + (nodeType==1 ? string("server") : string("client"))); return; } _localPort = localPort; initServer(); beginThread(); nodeType = 2; }
void btThreadPool::startThreads(int numThreads) { btAssert(numThreads > 0); btAssert(!m_bThreadsStarted); m_bThreadsStarted = true; m_numThreads = numThreads; m_pThreadInfo.resize(numThreads); for (int i = 0; i < numThreads; i++) { m_pThreadInfo[i] = (btThreadPoolInfo *)btAlloc(sizeof(btThreadPoolInfo)); btThreadPoolInfo *pInfo = m_pThreadInfo[i]; pInfo->threadId = i; beginThread(pInfo); } }
//CLIENT SETUP void TalkyBase::setup(string remoteHost, int remotePort) { if (nodeType != 0) { throw(string("Already initialised as node type ") + (nodeType==1 ? string("server") : string("client"))); return; } _remoteHost = remoteHost; _remotePort = remotePort; initClient(); beginThread(); nodeType = 1; }
thread(void (*f)()) : f_(f) { beginThread(); }