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;
}
Ejemplo n.º 2
0
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);
    }
}
Ejemplo n.º 3
0
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 ();
}
Ejemplo n.º 4
0
/*
 * Yield processor to another thread of the same priority.
 */
void
java_lang_Thread_yield(void)
{
	yieldThread();
}