Exemplo n.º 1
0
static void *Worker( void *arg ) {
	TYPE id = (size_t)arg;
	uint64_t entry;
#ifdef FAST
	unsigned int cnt = 0, oid = id;
#endif // FAST

	for ( int r = 0; r < RUNS; r += 1 ) {
		entry = 0;
		while ( stop == 0 ) {
			// step 1, select a ticket
			choosing[id] = 1;							// entry protocol
			Fence();									// force store before more loads
			TYPE max = 0;								// O(N) search for largest ticket
			for ( int j = 0; j < N; j += 1 ) {
				TYPE v = ticket[j];						// could change so must copy
				if ( max < v ) max = v;
			} // for
#if 1
			max += 1;									// advance ticket
			ticket[id] = max;
			choosing[id] = 0;
			Fence();									// force store before more loads
			// step 2, wait for ticket to be selected
			for ( int j = 0; j < N; j += 1 ) {			// check other tickets
				while ( choosing[j] == 1 ) Pause();		// busy wait if thread selecting ticket
				while ( ticket[j] != 0 &&				// busy wait if choosing or
						( ticket[j] < max ||			//  greater ticket value or lower priority
						( ticket[j] == max && j < id ) ) ) Pause();
			} // for
#else
			ticket[id] = max + 1;						// advance ticket
			choosing[id] = 0;
			Fence();									// force store before more loads
			// step 2, wait for ticket to be selected
			for ( int j = 0; j < N; j += 1 ) {			// check other tickets
				while ( choosing[j] == 1 ) Pause();		// busy wait if thread selecting ticket
				while ( ticket[j] != 0 &&				// busy wait if choosing or
						( ticket[j] < ticket[id] ||		//  greater ticket value or lower priority
						( ticket[j] == ticket[id] && j < id ) ) ) Pause();
			} // for
#endif
			CriticalSection( id );
			ticket[id] = 0;								// exit protocol
#ifdef FAST
			id = startpoint( cnt );						// different starting point each experiment
			cnt = cycleUp( cnt, NoStartPoints );
#endif // FAST
			entry += 1;
		} // while
#ifdef FAST
		id = oid;
#endif // FAST
		entries[r][id] = entry;
		__sync_fetch_and_add( &Arrived, 1 );
		while ( stop != 0 ) Pause();
		__sync_fetch_and_add( &Arrived, -1 );
	} // for
	return NULL;
} // Worker
Exemplo n.º 2
0
static void *Worker( void *arg ) {
	TYPE id = (size_t)arg;
	uint64_t entry;
#ifdef FAST
	unsigned int cnt = 0, oid = id;
#endif // FAST

	int j;

	for ( int r = 0; r < RUNS; r += 1 ) {
		entry = 0;
		while ( stop == 0 ) {
			flag[id] = 1;
			Fence();									// force store before more loads
			for ( j = 0; j < N; j += 1 )				// wait until doors open
				await( flag[j] < 3 );
			flag[id] = 3;								// close door 1
			Fence();									// force store before more loads
			for ( j = 0; j < N; j += 1 )				// check for 
				if ( flag[j] == 1 ) {					//   others in group ?
					flag[id] = 2;						// enter waiting room
					Fence();							// force store before more loads
				  L: for ( int k = 0; k < N; k += 1 )	// wait for
						if ( flag[k] == 4 ) goto fini;	//   door 2 to open
					goto L;
				  fini: ;
				} // if
			flag[id] = 4;								// open door 2
			Fence();									// force store before more loads
//			for ( j = 0; j < N; j += 1 )				// wait for all threads in waiting room
//				await( flag[j] < 2 || flag[j] > 3 );	//    to pass through door 2
			for ( j = 0; j < id; j += 1 )				// service threads in priority order
				await( flag[j] < 2 );
			CriticalSection( id );
			for ( j = id + 1; j < N; j += 1 )			// wait for all threads in waiting room
				await( flag[j] < 2 || flag[j] > 3 );	//    to pass through door 2
			flag[id] = 0;
#ifdef FAST
			id = startpoint( cnt );						// different starting point each experiment
			cnt = cycleUp( cnt, NoStartPoints );
#endif // FAST
			entry += 1;
		} // while
#ifdef FAST
		id = oid;
#endif // FAST
		entries[r][id] = entry;
		__sync_fetch_and_add( &Arrived, 1 );
		while ( stop != 0 ) Pause();
		__sync_fetch_and_add( &Arrived, -1 );
	} // for
	return NULL;
} // Worker
Exemplo n.º 3
0
static void *Worker( void *arg ) {
	TYPE id = (size_t)arg;
	uint64_t entry;
#ifdef FAST
	unsigned int cnt = 0, oid = id;
#endif // FAST

	TYPE copy[N];
	int j;

	for ( int r = 0; r < RUNS; r += 1 ) {
		entry = 0;
		while ( stop == 0 ) {
			c[id] = 1;									// stage 1, establish FCFS
			Fence();									// force store before more loads
			for ( j = 0; j < N; j += 1 )				// copy turn values
				copy[j] = turn[j];
//			turn[id] = cycleUp( turn[id], 4 );			// advance my turn
			turn[id] = cycleUp( turn[id], 3 );			// advance my turn
			v[id] = 1;
			c[id] = 0;
			Fence();									// force store before more loads
			for ( j = 0; j < N; j += 1 )
				while ( c[j] != 0 || (v[j] != 0 && copy[j] == turn[j]) ) Pause();
		  L: intents[id] = 1;							// B-L
			Fence();									// force store before more loads
			for ( j = 0; j < id; j += 1 )				// stage 2, high priority search
				if ( intents[j] != 0 ) {
					intents[id] = 0;
					Fence();							// force store before more loads
					while ( intents[j] != 0 ) Pause();
					goto L;
				} // if
			for ( j = id + 1; j < N; j += 1 )			// stage 3, low priority search
				while ( intents[j] != 0 ) Pause();
			CriticalSection( id );
			v[id] = intents[id] = 0;					// exit protocol
#ifdef FAST
			id = startpoint( cnt );						// different starting point each experiment
			cnt = cycleUp( cnt, NoStartPoints );
#endif // FAST
			entry += 1;
		} // while
#ifdef FAST
		id = oid;
#endif // FAST
		entries[r][id] = entry;
		__sync_fetch_and_add( &Arrived, 1 );
		while ( stop != 0 ) Pause();
		__sync_fetch_and_add( &Arrived, -1 );
	} // for
	return NULL;
} // Worker
static void *Worker( void *arg ) {
    TYPE id = (size_t)arg;
	uint64_t entry;
#ifdef FAST
	unsigned int cnt = 0, oid = id;
#endif // FAST

    for ( int r = 0; r < RUNS; r += 1 ) {
        entry = 0;
        while ( atomic_load(&stop) == 0 ) {
            atomic_store(&states[id*PADRATIO], LOCKED);
            while (1) {
                int lturn = atomic_load(&turn);
                if (!validate_left(id, lturn)) {
                    atomic_store(&states[id*PADRATIO], WAITING);
                    while (1) {
                        if (validate_left(id, lturn) && lturn == atomic_load_explicit(&turn, memory_order_acquire)) break;
                        Pause();
                        lturn = atomic_load_explicit(&turn, memory_order_acquire);
                    }
                    atomic_store(&states[id*PADRATIO], LOCKED);
                    continue;
                }
                while (lturn == atomic_load_explicit(&turn, memory_order_acquire)) {
                    if (validate_right(id, lturn)) break;
                    Pause();
                }
                if (lturn == atomic_load_explicit(&turn, memory_order_acquire)) break;
            }
			CriticalSection( id );						// critical section
			int lturn = (atomic_load_explicit(&turn, memory_order_relaxed)+1) % N;
			atomic_store_explicit(&turn, lturn, memory_order_relaxed);
			atomic_store_explicit(&states[id*PADRATIO], UNLOCKED, memory_order_release); // exit protocol
#ifdef FAST
			id = startpoint( cnt );						// different starting point each experiment
			cnt = cycleUp( cnt, NoStartPoints );
#endif // FAST
			entry += 1;
		} // while
#ifdef FAST
		id = oid;
#endif // FAST
		entries[r][id] = entry;
        atomic_fetch_add( &Arrived, 1 );
        while ( atomic_load(&stop) != 0 ) Pause();
        atomic_fetch_add( &Arrived, -1 );
	} // for
	return NULL;
} // Worker
Exemplo n.º 5
0
static void *Worker( void *arg ) {
	TYPE id = (size_t)arg;
	uint64_t entry;
#ifdef FAST
	unsigned int cnt = 0, oid = id;
#endif // FAST

	TYPE temp;

	for ( int r = 0; r < RUNS; r += 1 ) {
		entry = 0;
		while ( stop == 0 ) {
			if ( id == 0 ) {
				temp = Q[1];
				Q[0] = temp == Z ? T : (temp == T ? T : F);
				Fence();
				temp = Q[1];
				Q[0] = temp == Z ? Q[0] : (temp == T ? T : F);
				Fence();
				await( Q[1] != Q[0] );
			} else {
				temp = Q[0];
				Q[1] = temp == Z ? T : (temp == T ? F : T);
				Fence();
				temp = Q[0];
				Q[1] = temp == Z ? Q[1] : (temp == T ? F : T);
				Fence();
				await( Q[0] == Z || Q[0] == Q[1] );
			} // for
			CriticalSection( id );
			Q[id] = Z;
#ifdef FAST
			id = startpoint( cnt );						// different starting point each experiment
			cnt = cycleUp( cnt, NoStartPoints );
#endif // FAST
			entry += 1;
		} // while
#ifdef FAST
		id = oid;
#endif // FAST
		entries[r][id] = entry;
		__sync_fetch_and_add( &Arrived, 1 );
		while ( stop != 0 ) Pause();
		__sync_fetch_and_add( &Arrived, -1 );
	} // for
	return NULL;
} // Worker
Exemplo n.º 6
0
static void *Worker( void *arg ) {
	TYPE id = (size_t)arg;
	uint64_t entry;
#ifdef FAST
	unsigned int cnt = 0, oid = id;
#endif // FAST

	for ( int r = 0; r < RUNS; r += 1 ) {
		entry = 0;
		while ( stop == 0 ) {
		  L0: control[id] = WantIn;						// entry protocol
			Fence();									// force store before more loads
			// step 1, wait for threads with higher priority
		  L1: for ( int j = HIGH; j != id; j = cycleUp( j, N ) )
				if ( control[j] != DontWantIn ) { Pause(); goto L1; } // restart search
			control[id] = EnterCS;
			Fence();									// force store before more loads
			// step 2, check for any other thread finished step 1
			for ( int j = 0; j < N; j += 1 )
				if ( j != id && control[j] == EnterCS ) goto L0;
			if ( control[HIGH] != DontWantIn && HIGH != id ) goto L0;
			HIGH = id;									// its now ok to enter
			CriticalSection( id );
			// look for any thread that wants in other than this thread
//			for ( int j = cycleUp( id + 1, N );; j = cycleUp( j, N ) ) // exit protocol
			for ( int j = cycleUp( HIGH + 1, N );; j = cycleUp( j, N ) ) // exit protocol
				if ( control[j] != DontWantIn ) { HIGH = j; break; }
			control[id] = DontWantIn;
#ifdef FAST
			id = startpoint( cnt );						// different starting point each experiment
			cnt = cycleUp( cnt, NoStartPoints );
#endif // FAST
			entry += 1;
		} // while
#ifdef FAST
		id = oid;
#endif // FAST
		entries[r][id] = entry;
		__sync_fetch_and_add( &Arrived, 1 );
		while ( stop != 0 ) Pause();
		__sync_fetch_and_add( &Arrived, -1 );
	} // for
	return NULL;
} // Worker
Exemplo n.º 7
0
static void *Worker( void *arg ) {
	TYPE id = (size_t)arg;
	uint64_t entry;
#ifdef FAST
	unsigned int cnt = 0, oid = id;
#endif // FAST

	for ( int r = 0; r < RUNS; r += 1 ) {
		entry = 0;
		while ( stop == 0 ) {
		  L: intents[id] = WantIn;
			Fence();									// force store before more loads
			for ( int j = 0; j < id; j += 1 ) {			// check if thread with higher id wants in
//			for ( int j = id - 1; j >= 0; j -= 1 ) {
				if ( intents[j] == WantIn ) {
					intents[id] = DontWantIn;
					Fence();							// force store before more loads
					while ( intents[j] == WantIn ) Pause();
					goto L;
				} // if
			} // for
			for ( int j = id + 1; j < N; j += 1 )
				while ( intents[j] == WantIn ) Pause();
			CriticalSection( id );						// critical section
			intents[id] = DontWantIn;					// exit protocol
#ifdef FAST
			id = startpoint( cnt );						// different starting point each experiment
			cnt = cycleUp( cnt, NoStartPoints );
#endif // FAST
			entry += 1;
		} // while
#ifdef FAST
		id = oid;
#endif // FAST
		entries[r][id] = entry;
		__sync_fetch_and_add( &Arrived, 1 );
		while ( stop != 0 ) Pause();
		__sync_fetch_and_add( &Arrived, -1 );
	} // for
	return NULL;
} // Worker
Exemplo n.º 8
0
static void *Worker( void *arg ) {
	TYPE id = (size_t)arg;
	uint64_t entry;
	int other = inv( id );
#ifdef FAST
	unsigned int cnt = 0, oid = id;
#endif // FAST

	for ( int r = 0; r < RUNS; r += 1 ) {
		entry = 0;
		while ( atomic_load(&stop) == 0 ) {
		    if ( id == 0 ) {
	            atomic_store(intents[id], WantIn);                       // declare intent
	            if ( atomic_load(intents[other]) == WantIn ) { // other thread want in ?
	                if ( atomic_load_explicit(last, memory_order_acquire) == id ) {                     // low priority task ?
	                    atomic_store(intents[id], DontWantIn);           // retract intent
	                    await( atomic_load(last) != id );                // low priority busy wait
	                    atomic_store(intents[id], WantIn);               // re-declare intent
	                } // if
	                await( atomic_load(intents[other]) == DontWantIn );  // high priority busy wait
	            } // if
		        CriticalSection( id );                      // critical section
	            atomic_store_explicit(last, id, memory_order_release);                                  // exit protocol
	            atomic_store_explicit(intents[id], DontWantIn, memory_order_release);
		    }
#ifdef FAST
			id = startpoint( cnt );						// different starting point each experiment
			cnt = cycleUp( cnt, NoStartPoints );
#endif // FAST
			entry += 1;
		} // while
#ifdef FAST
		id = oid;
#endif // FAST
		entries[r][id] = entry;
        atomic_fetch_add( &Arrived, 1 );
        while ( atomic_load(&stop) != 0 ) Pause();
        atomic_fetch_add( &Arrived, -1 );
	} // for
	return NULL;
} // Worker
Exemplo n.º 9
0
static void *Worker( void *arg ) {
	TYPE id = (size_t)arg;
	uint64_t entry;
#ifdef FAST
	unsigned int cnt = 0, oid = id;
#endif // FAST

	unsigned int lid;									// local id at each tree level

	for ( int r = 0; r < RUNS; r += 1 ) {
		entry = 0;
		while ( stop == 0 ) {
			lid = id;									// entry protocol
			for ( int lv = 0; lv < depth; lv += 1 ) {
				binary_prologue( lid & 1, &t[lv][lid >> 1] );
				lid >>= 1;								// advance local id for next tree level
			} // for

			CriticalSection( id );

			for ( int lv = depth - 1; lv >= 0; lv -= 1 ) { // exit protocol, retract reverse order
				lid = id >> lv;
				binary_epilogue( lid & 1, &t[lv][lid >> 1] );
			} // for
#ifdef FAST
			id = startpoint( cnt );						// different starting point each experiment
			cnt = cycleUp( cnt, NoStartPoints );
#endif // FAST
			entry += 1;
		} // while
#ifdef FAST
		id = oid;
#endif // FAST
		entries[r][id] = entry;
		__sync_fetch_and_add( &Arrived, 1 );
		while ( stop != 0 ) Pause();
		__sync_fetch_and_add( &Arrived, -1 );
	} // for
	return NULL;
} // Worker
Exemplo n.º 10
0
static void *Worker( void *arg ) {
    TYPE id = (size_t)arg;
    uint64_t entry;

	int other = inv( id );								// int is better than TYPE

#ifdef FAST
	unsigned int cnt = 0, oid = id;
#endif // FAST

    for ( int r = 0; r < RUNS; r += 1 ) {
		entry = 0;
		while ( stop == 0 ) {
			intents[id] = WantIn;						// entry protocol
			last = id;									// RACE
			Fence();									// force store before more loads
			if ( FASTPATH( intents[other] != DontWantIn ) )	// local spin
				while ( last == id ) Pause();			// busy wait
			CriticalSection( id );
			intents[id] = DontWantIn;					// exit protocol
			last = id;
#ifdef FAST
			id = startpoint( cnt );						// different starting point each experiment
			other = inv( id );
			cnt = cycleUp( cnt, NoStartPoints );
#endif // FAST
			entry += 1;
		} // while
#ifdef FAST
		id = oid;
		other = inv( id );
#endif // FAST
		entries[r][id] = entry;
		__sync_fetch_and_add( &Arrived, 1 );
		while ( stop != 0 ) Pause();
		__sync_fetch_and_add( &Arrived, -1 );
    } // for
	return NULL;
} // Worker
Exemplo n.º 11
0
static void *Worker( void *arg ) {
	TYPE id = (size_t)arg;
#ifdef FAST
	unsigned int cnt = 0, oid = id;
#endif // FAST
	uint64_t entry;

	for ( int r = 0; r < RUNS; r += 1 ) {
		entry = 0;
		while ( stop == 0 ) {
		  L0: control[id] = WantIn;						// entry protocol
			Fence();									// force store before more loads
		  L1: for ( int j = turn; j != id; j = cycleDown( j, N ) )
				if ( control[j] != DontWantIn ) { Pause(); goto L1; } // restart search
			control[id] = EnterCS;
			Fence();									// force store before more loads
			for ( int j = N - 1; j >= 0; j -= 1 )
				if ( j != id && control[j] == EnterCS ) goto L0;
			CriticalSection( id );
			// cycle through threads
			if ( control[turn] == DontWantIn || turn == id ) // exit protocol
				turn = cycleDown( turn, N );
			control[id] = DontWantIn;
#ifdef FAST
			id = startpoint( cnt );						// different starting point each experiment
			cnt = cycleUp( cnt, NoStartPoints );
#endif // FAST
			entry += 1;
		} // while
#ifdef FAST
		id = oid;
#endif // FAST
		entries[r][id] = entry;
		__sync_fetch_and_add( &Arrived, 1 );
		while ( stop != 0 ) Pause();
		__sync_fetch_and_add( &Arrived, -1 );
	} // for
	return NULL;
} // Worker
Exemplo n.º 12
0
//*************************************************************************************************
// Constructor
//*************************************************************************************************
JobManager::JobManager(void) 
	: _workerThreads(0), _runManager(false)
{ 
	_criticalSection = CriticalSection();
}
Exemplo n.º 13
0
// add a variable to the environment or alias to the alias list
int PASCAL add_list( LPTSTR pszVariable, TCHAR _far *pchList )
{
	LPTSTR pszLine;
	TCHAR _far *pszVarName, _far *pszArgument, _far *pszEndOfList, _far *pszLastVariable;
	unsigned int uLength;
	int nError = 0;

	if ( pchList == 0L )
		pchList = glpEnvironment;

	pszLine = pszVariable;
	if ( *pszLine == _TEXT('=') ) {
		return ( error( ERROR_4DOS_BAD_SYNTAX, pszVariable ));
	}

	for ( ; (( *pszLine ) && ( *pszLine != _TEXT('=') )); pszLine++ ) {

		if ( pchList != glpEnvironment ) {

			if ( iswhite( *pszLine )) {
				strcpy( pszLine, skipspace( pszLine ) );
				break;
			}
		}
		else	    // ensure environment entry is in upper case
			*pszLine = (unsigned char)_ctoupper( *pszLine );
	}

	// stupid kludge to strip quotes from PATH for compatibility with
	//   COMMAND.COM
	if (( fWin95 ) && ( pchList == glpEnvironment )) {

		char szVarName[8];

		if (( uLength = ( pszLine - pszVariable )) > 7 )
			uLength = 7;

		sprintf( szVarName, "%.*s", uLength, pszVariable );
		if ( stricmp( szVarName, PATH_VAR ) == 0 )
			StripQuotes( pszLine );
	}

	if ( *pszLine == _TEXT('=') ) {

		// point to the first char of the argument
		pszLine++;

		// collapse whitespace around '=' in aliases, but not in env
		//   variables, for COMMAND.COM compatibility (set abc def= ghi)
		if ( pchList != glpEnvironment )
			strcpy( pszLine, skipspace( pszLine ));

	} else if ( *pszLine ) {
		// add the missing '='
		strins( pszLine, _TEXT("=") );
		pszLine++;
	}

	// removing single back quotes at the beginning and end of an alias
	//   argument (they're illegal there; the user is probably making a
	//   mistake with ALIAS /R)
	if (( *pszLine == SINGLE_QUOTE ) && ( pchList != glpEnvironment )) {

		// remove leading single quote
		strcpy( pszLine, pszLine + 1 );

		// remove trailing single quote
		if ((( uLength = strlen( pszLine )) != 0 ) && ( pszLine[--uLength] == SINGLE_QUOTE ))
			pszLine[uLength] = _TEXT('\0');
	}

	// block other processes & threads while updating list
	if ( pchList != glpEnvironment ) {
		// disable task switches under Windows and DESQview
		CriticalSection( 1 );
	}

	// get pointers to beginning & end of list space
	pszEndOfList = pchList + ((( pchList == glpAliasList ) ? gpIniptr->AliasSize : gpIniptr->EnvSize ) - 4 );

	// get pointer to end of environment or alias variables
	pszLastVariable = end_of_env( pchList );

	uLength = strlen( pszVariable ) + 1;

	// check for modification or deletion of existing entry
	if (( pszArgument = get_list( pszVariable, pchList )) != 0L ) {

		// get the start of the alias or variable name
		for ( pszVarName = pszArgument; (( pszVarName > pchList ) && ( pszVarName[-1] != _TEXT('\0') )); pszVarName-- )
			;

		if ( *pszLine == _TEXT('\0') ) {
			// delete an alias or environment variable
			_fmemmove( pszVarName, next_env( pszVarName ), (unsigned int)( (ULONG_PTR)pszLastVariable - (ULONG_PTR)next_env(pszVarName)) + sizeof(TCHAR));
		} else {
			// get the relative length (vs. the old variable)
			uLength = strlen( pszLine ) - _fstrlen( pszArgument );
		}
	}

	if ( *pszLine != _TEXT('\0') ) {

		// check for out of space
		if (( pszLastVariable + ( uLength * sizeof(TCHAR) )) >= pszEndOfList ) {

			if ( pchList == glpAliasList )
				nError = error( ERROR_4DOS_OUT_OF_ALIAS, NULL );
			else if ( pchList == glpEnvironment )
				nError = error( ERROR_4DOS_OUT_OF_ENVIRONMENT, NULL);
			else
				nError = error( ERROR_NOT_ENOUGH_MEMORY, NULL );
			goto add_bye;
		}

		if ( pszArgument != 0L ) {

			// modify an existing value
			//   adjust the space & insert new value
			pszVarName = next_env( pszVarName );
			_fmemmove(( pszVarName + uLength ), pszVarName, (unsigned int)(( (ULONG_PTR)pszLastVariable - (ULONG_PTR)pszVarName ) + sizeof(TCHAR) ));
			_fstrcpy( pszArgument, pszLine );

		} else {
			// put it at the end & add an extra null
			_fstrcpy( pszLastVariable, pszVariable );
			pszLastVariable[uLength] = _TEXT('\0');
		}
	}

add_bye:
	if ( pchList != glpEnvironment ) {
		// re-enable task switches under Windows and DESQview
		CriticalSection( 0 );
	}

	return nError;
}
Exemplo n.º 14
0
static void *Worker( void *arg ) {
	TYPE id = (size_t)arg;
	uint64_t entry;

	int other = inv( id );								// int is better than TYPE

#ifdef FAST
	unsigned int cnt = 0, oid = id;
#endif // FAST

	for ( int r = 0; r < RUNS; r += 1 ) {
		entry = 0;
		while ( stop == 0 ) {
			for ( ;; ) {
#ifdef FLICKER
				for ( int i = 0; i < 100; i += 1 ) intents[id] = i % 2; // flicker
#endif // FLICKER
				intents[id] = WantIn;					// declare intent
				// Necessary to prevent the read of intents[other] from floating above the assignment
				// intents[id] = WantIn, when the hardware determines the two subscripts are different.
				Fence();								// force store before more loads
			  if ( FASTPATH( intents[other] == DontWantIn ) ) break;
				if ( last == id ) {
#ifdef FLICKER
					for ( int i = 0; i < 100; i += 1 ) intents[id] = i % 2; // flicker
#endif // FLICKER
					intents[id] = DontWantIn;
					// Optional fence to prevent LD of "last" from being lifted above store of
					// intends[id]=DontWantIn. Because a thread only writes its own id into "last",
					// and because of eventual consistency (writes eventually become visible),
					// the fence is conservative.
					//Fence();							// force store before more loads
					await( last != id );				// low priority busy wait
				} // if
			} // for
			CriticalSection( id );
#ifdef FLICKER
			for ( int i = id; i < 100; i += 1 ) last = i % 2; // flicker
#endif // FLICKER
			last = id;									// exit protocol
#ifdef FLICKER
			for ( int i = 0; i < 100; i += 1 ) intents[id] = i % 2; // flicker
#endif // FLICKER
			intents[id] = DontWantIn;

#ifdef FAST
			id = startpoint( cnt );						// different starting point each experiment
			other = inv( id );
			cnt = cycleUp( cnt, NoStartPoints );
#endif // FAST
			entry += 1;
		} // while
#ifdef FAST
		id = oid;
		other = inv( id );
#endif // FAST
		entries[r][id] = entry;
		__sync_fetch_and_add( &Arrived, 1 );
		while ( stop != 0 ) Pause();
		__sync_fetch_and_add( &Arrived, -1 );
	} // for
	return NULL;
} // Worker
Exemplo n.º 15
0
namespace bvr20983
{
  template< class charT,class traits >
  CriticalSection LogStreamBuf<charT,traits>::m_criticalSection = CriticalSection();

  /**
   *
   */
  template< class charT,class traits >
  LogStreamBuf<charT,traits>::LogStreamBuf()
  { m_pLogStream = NULL;
    m_dumpPrefix = true;
    
    setp(m_buffer,m_buffer+sizeof(m_buffer)/sizeof(m_buffer[0]));
  }

  /**
   *
   */
  template< class charT,class traits >
  LogStreamBuf<charT,traits>::~LogStreamBuf()
  { 
  }
      
  template< class charT,class traits >
  bool LogStreamBuf<charT,traits>::ContainsEndl() const
  { bool result = pptr() - pbase()>0 ? false : true;
  
    charT* m = pptr();
    for( charT* i = pbase();i<m;i++ )
      if( *i==_T('\n') )
      { result = true;
      
        break;
      } // of if
    
    return result;
  } 
  
  /**
   *
   */
  template< class charT,class traits >
  typename LogStreamBuf<charT,traits>::int_type 
  LogStreamBuf<charT,traits>::overflow(typename LogStreamBuf<charT,traits>::int_type c)
  { Critical crit(m_criticalSection);

    assert( m_pLogStream!=NULL );
    
    streamsize len = pptr() - pbase();
    
    if( len>0 )
    { AppenderList::iterator iter;
    
      for( iter=m_appenders.begin();iter!=m_appenders.end();iter++ )
      { LogAppender<TCHAR>& logAppender = **iter;
      
        logAppender.Dump(m_pLogStream->GetLevel(),
                         m_pLogStream->GetSourceFileName(),
                         m_pLogStream->GetSourceLineNo(),
                         m_pLogStream->GetIndent(),
                         m_dumpPrefix,
                         pbase(),len
                        );
      } // of for
      
      if( m_dumpPrefix )
        m_dumpPrefix = false;
          
      if( ContainsEndl() )
      { m_dumpPrefix = true;
        //m_pLogStream->SetLevel(LogLevel<charT,traits>::INFO_LEVEL);
        //m_pLogStream->SetSourceLineNo(-1);
      } // of if
    } // of if     

    pbump(-len);
    
    if( traits_type::not_eof(c) )
      sputc(c);
  
    return traits_type::not_eof(c);
  } // of LogStreamBuf<charT,traits>::overflow()

  /**
   *
   */
  template< class charT,class traits >
  int LogStreamBuf<charT,traits>::sync()
  { overflow();
  
    return 0;
  } // of int LogStreamBuf<charT,traits>::sync()


  /**
   *
   */
  template< class charT,class traits >
  OutputDebugStreamBuf<charT,traits>::OutputDebugStreamBuf()
  { setp(m_buffer,m_buffer+sizeof(m_buffer)/sizeof(m_buffer[0])); }

  /**
   *
   */
  template< class charT,class traits >
  typename OutputDebugStreamBuf<charT,traits>::int_type 
  OutputDebugStreamBuf<charT,traits>::overflow(typename OutputDebugStreamBuf<charT,traits>::int_type c)
  { streamsize len = pptr() - pbase();
    
    if( len>0 )
    { charT c = m_buffer[len];

      m_buffer[len] = _T('\0');

      OutputDebugString(pbase());

      m_buffer[len] = c;
    } // of if     

    pbump(-len);
    
    if( traits_type::not_eof(c) )
      sputc(c);
  
    return traits_type::not_eof(c);
  } // of OutputDebugStreamBuf<charT,traits>::overflow()

  /**
   *
   */
  template< class charT,class traits >
  int OutputDebugStreamBuf<charT,traits>::sync()
  { overflow();
  
    return 0;
  }
} // of namespace bvr20983
Exemplo n.º 16
0
namespace EmberNs
{
template<> unique_ptr<QTIsaac<ISAAC_SIZE, ISAAC_INT>> QTIsaac<ISAAC_SIZE, ISAAC_INT>::GlobalRand = unique_ptr<QTIsaac<ISAAC_SIZE, ISAAC_INT>>(new QTIsaac<ISAAC_SIZE, ISAAC_INT>());
template<> CriticalSection QTIsaac<ISAAC_SIZE, ISAAC_INT>::m_CS = CriticalSection();
}
Exemplo n.º 17
0
static void *Worker( void *arg ) {
	TYPE id = (size_t)arg;
	uint64_t entry;

	int other = inv( id );								// int is better than TYPE

#ifdef FAST
	unsigned int cnt = 0, oid = id;
#endif // FAST

	for ( int r = 0; r < RUNS; r += 1 ) {
		entry = 0;
		while ( stop == 0 ) {
#ifdef FLICKER
			for ( int i = 0; i < 100; i += 1 ) cc[id] = i % 2; // flicker
#endif // FLICKER
			cc[id] = WantIn;							// declare intent
			Fence();									// force store before more loads
			while ( cc[other] == WantIn ) {
				if ( FASTPATH( last == id ) ) {
#ifdef FLICKER
					for ( int i = 0; i < 100; i += 1 ) cc[id] = i % 2; // flicker
#endif // FLICKER
					cc[id] = DontWantIn;
					while( cc[other] == WantIn && last == id ) Pause();	// low priority busy wait
#ifdef FLICKER
					for ( int i = 0; i < 100; i += 1 ) cc[id] = i % 2; // flicker
#endif // FLICKER
					cc[id] = WantIn;					// declare intent
					Fence();							// force store before more loads
				} // if
			} // while
			CriticalSection( id );
			if ( last != id ) {
#ifdef FLICKER
				for ( int i = id; i < 100; i += 1 ) last = i % 2; // flicker
#endif // FLICKER
				last = id;
			} // if
#ifdef FLICKER
			for ( int i = 0; i < 100; i += 1 ) cc[id] = i % 2; // flicker
#endif // FLICKER
			cc[id] = DontWantIn;

#ifdef FAST
			id = startpoint( cnt );						// different starting point each experiment
			other = inv( id );
			cnt = cycleUp( cnt, NoStartPoints );
#endif // FAST
			entry += 1;
		} // while
#ifdef FAST
		id = oid;
		other = inv( id );
#endif // FAST
		entries[r][id] = entry;
		__sync_fetch_and_add( &Arrived, 1 );
		while ( stop != 0 ) Pause();
		__sync_fetch_and_add( &Arrived, -1 );
	} // for
	return NULL;
} // Worker