Example #1
0
void prime_process()
{
	register unsigned long h, i, j, tprimes=0;

	// Lock process_stage, copy it to local var, subtract 1 from process_stage, unlock it.
	b_smp_lock(lock);
	i = (process_stage * 2) + 1;
	process_stage--;
	b_smp_unlock(lock);

	h = processes * 2;

	// Process
	for(; i<=maxn; i+=h)
	{
		for(j=2; j<=i-1; j++)
		{
			if(i%j==0) break; // Number is divisble by some other number. So break out
		}
		if(i==j)
		{
			tprimes = tprimes + 1;
		}
	} // Continue loop up to max number

	// Add tprimes to primes.
	b_smp_lock(lock);
	primes = primes + tprimes;
	b_smp_unlock(lock);
}
Example #2
0
void *prime_process(void *param)
{
	register unsigned long h, i, j, tprimes=0;

	// Lock process_stage, copy it to local var, subtract 1 from process_stage, unlock it.
#ifdef BAREMETAL
	b_smp_lock(lock);
#else
	pthread_mutex_lock( &mutex1 );
#endif

	i = (process_stage * 2) + 1;
	process_stage--;

#ifdef BAREMETAL
	b_smp_unlock(lock);
#else
	pthread_mutex_unlock( &mutex1 );
#endif

	h = processes * 2;

	// Process
	for(; i<=max_number; i+=h)
	{
		for(j=2; j<=i-1; j++)
		{
			if(i%j==0) break; // Number is divisible by some other number. So break out
		}
		if(i==j)
		{
			tprimes = tprimes + 1;
		}
	} // Continue loop up to max number

	// Add tprimes to primes.
#ifdef BAREMETAL
	b_smp_lock(lock);
#else
	pthread_mutex_lock( &mutex1 );
#endif

	primes = primes + tprimes;

#ifdef BAREMETAL
	b_smp_unlock(lock);
#else
	pthread_mutex_unlock( &mutex1 );
#endif
}