- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to use Intel Thread Checker to analyze a Win32 console application that starts two threads that makes some computation in parallel.
The two threads are started with __beginthreadex. Unfortunately, I startthe application form theIntel Thread Checker enviroment the application itself freezes after the second__beginthreadex.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to use Intel Thread Checker to analyze a Win32 console application that starts two threads that makes some computation in parallel.
The two threads are started with __beginthreadex. Unfortunately, I startthe application form theIntel Thread Checker enviroment the application itself freezes after the second__beginthreadex.
I changed below example from CreateThread() to _beginthreadex(), Intel Thread Checker works well (can detect write/read error). Please visit https://premier.intel.com to submit a ticket with your test case. Regards, Peter
#include
#include
#include
#include
#define NUM_THREADS 4
#define MAX_NUMBERS 100000
long ThreadNums[NUM_THREADS];
HANDLE ThreadHandles[NUM_THREADS];
long Primes[MAX_NUMBERS];
long PrimeCount;
CRITICAL_SECTION Primes_CS;
//DWORD WINAPI FindPrimes (void * Arg)
unsigned int WINAPI FindPrimes (void * Arg)
{
long ThreadNum = *(long *) Arg;
long BlockSize, start, end, stride;
long number, factor;
BlockSize = MAX_NUMBERS/NUM_THREADS;
// If the original MAX_NUMBERS and NUM_THREADS were
// changed, BlockSize could be odd.
if (BlockSize % 2) ++BlockSize;
start = ThreadNum * BlockSize + 1;
end = (ThreadNum == (NUM_THREADS - 1) ? MAX_NUMBERS :
(ThreadNum * BlockSize + BlockSize));
stride = 2;
if (start == 1) start += stride;
for (number = start; number < end; number += stride)
{
factor = 3;
while ((number % factor) != 0 ) factor += 2;
if ( factor == number )
{
// EnterCriticalSection( &Primes_CS );
Primes[PrimeCount] = number;
PrimeCount++;
// LeaveCriticalSection( &Primes_CS );
}
}
return 0;
}
int main()
{
InitializeCriticalSection( &Primes_CS );
PrimeCount = 0;
Primes[PrimeCount++] = 2; // handle special case
printf( "Determining primes from 1 - %d n", MAX_NUMBERS );
for (long thread = 0; thread < NUM_THREADS; ++thread)
{
ThreadNums[thread] = thread;
ThreadHandles[thread] =
//CreateThread(0, 0, FindPrimes, (void *) &(ThreadNums[thread]), 0, 0);
(HANDLE)_beginthreadex(0, 0, FindPrimes, (void *) &(ThreadNums[thread]), 0, 0);
}
WaitForMultipleObjects( NUM_THREADS, ThreadHandles, TRUE, INFINITE );
printf( "Found %d primesn", PrimeCount );
return 0;
}

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page