bool LazyInstanceState::needConstruction() { AtomicType state = loadAcquire(&mState); if (mState == STATE_DONE) return false; state = atomicCompareAndSwap(&mState, STATE_INIT, STATE_CONSTRUCTING); if (state == STATE_INIT) return true; do { yieldThread(); state = loadAcquire(&mState); } while (state != STATE_DONE); return false; }
void printMyThreadForThread0(int iter) { int tid = getThread(); int i; int j; spawnThread(printMyThread,iter); // 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); } }
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 (); }
/* * Yield processor to another thread of the same priority. */ void java_lang_Thread_yield(void) { yieldThread(); }