int AsyncServiceClientState::enqueueRequest(AsyncCallState* state) { int rv = spawnThread(AsyncServiceClientStateImpl::doRpc, this); if (rv == 0) { pImpl->requests.enqueue(state); } return rv; }
void VSThreadPool::wakeThread() { if (activeThreads < maxThreads) { if (idleThreads == 0) // newly spawned threads are active so no need to notify an additional thread spawnThread(); else newWork.notify_one(); } }
void createChild(void *function, test_ll_t *test) { hThread_t hTmpThread; hTmpThread = spawnThread(function, test); if (ISTHREADVALID(hTmpThread)) { test->hThread = hTmpThread; } else { pMsg(ERR, test->args, "%d : Could not create child thread...\n", GETLASTERROR()); exit(GETLASTERROR()); } }
void printMyThread(int iter) { int tid = getThread(); int i; int j; // delay for( i=0; i<NUMYIELDS; i++) { // Delay(100); Printf("%d ",iter); for(j=0; (j<tid); j++) Printf("."); Printf("T%d \n", tid); yieldThread((tid+1)%MAXTHREADS); } if(tid!=1) spawnThread(printMyThread,iter+1); else spawnThread(printMyThreadForThread0,iter+1); }
void Main () { int i, me; void printMyThread(); initThreads (); me = getThread (); for(i=1; i<MAXTHREADS; i++) spawnThread(printMyThread,0); for (i = 0; i < NUMYIELDS; i++) { Printf("0 T%d\n",me); yieldThread(1); } exitThread (); }
/* * This function will create children for us based on the action specified * during the call. if we cannot create a child, we fail and exit with * errno as the exit status. */ void CreateTestChild(void *function, test_ll_t *test) { thread_struct_t *pNewThread; hThread_t hTmpThread; hTmpThread = spawnThread(function, test); if (ISTHREADVALID(hTmpThread)) { if ((pNewThread = (thread_struct_t *) ALLOC(sizeof(thread_struct_t))) == NULL) { pMsg(ERR, test->args, "%d : Could not allocate memory for child thread...\n", GETLASTERROR()); exit(GETLASTERROR()); } test->env->kids++; memset(pNewThread, 0, sizeof(thread_struct_t)); pNewThread->next = test->env->pThreads; test->env->pThreads = pNewThread; test->env->pThreads->hThread = hTmpThread; } else { pMsg(ERR, test->args, "%d : Could not create all child threads.\n", GETLASTERROR()); pMsg(INFO, test->args, "Total Number of Threads created was %u\n", test->env->kids); exit(GETLASTERROR()); } }