Hi all,
Attached is a sample program, originally written to find out about the impact of using epoll on performance.
However, the program doesn't run properly. When running it, I get deadlocked.
Does anyone have any explanation? Is it a bug in my Win32 code?
err:ntdll:RtlpWaitForCriticalSection section 0x4017fec0 "?" wait timed out in thread 0009, blocked by 0000, retrying (60 sec)
Shachar
-- Shachar Shemesh Lingnu Open Source Consulting ltd. http://www.lingnu.com/
#include <windows.h> #include <stdio.h>
#define NUMTHREADS 3000 int flag; int count; DWORD WINAPI ThreadMain( LPVOID lpParam ) { HANDLE hmutex=CreateMutex( NULL, FALSE, "ThreadCreationTest"); int i=0; for( i=0; i<100; ++i ) { DWORD dwWait=WaitForSingleObject(hmutex,INFINITE); switch( dwWait ) { case WAIT_OBJECT_0: { int oldcount=count; if( flag ) fprintf(stderr, "No mutual exclusion!\n"); flag=1; oldcount++; count=oldcount; flag=0; } ReleaseMutex(hmutex); break; default: fprintf(stderr, "Didn't get mutex %lx\n", dwWait ); break; } } CloseHandle(hmutex); printf("Thread %d exiting with count at %d\n", lpParam, count ); return 0; } int main( int argc, char *argv ) { int i; HANDLE threads[NUMTHREADS]; flag=0; count=0; for( i=0; i<NUMTHREADS; ++i ){ DWORD threadid; threads[i]=CreateThread(NULL, 0, ThreadMain, (LPVOID)i, 0, &threadid); if( threads[i]==NULL) fprintf(stderr, "Failed to create thread %lx\n", GetLastError() ); } WaitForMultipleObjects(NUMTHREADS, threads, TRUE, INFINITE); fprintf(stderr,"Program exit %d\n", count); return 0; }