}
DWORD WINAPIWriteToDatabase( LPVOID lpParam )
{
DWORDdwCount=0, dwWaitResult;
//Request ownership of mutex.
while(dwCount < 100 )
{
dwWaitResult = WaitForSingleObject(
ghMutex, // handle to mutex
INFINITE); // no time-out interval
switch(dwWaitResult)
{
// Thethread got ownership of the mutex
caseWAIT_OECT_0:
__try{
g_x++;
//TODO: Write to the database
printf('Thread %d writing to database\n',
GetCurrentThreadId());
dwCount++;
}
__finally {
//Release ownership of the mutex object
if (!ReleaseMutex(ghMutex))
{
//Deal with error.
}
}
break;
// Thethread got ownership of an abandoned mutex
caseWAIT_ABANDONED:
returnFALSE;
}
}
returnTRUE;
}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-25584-3.html
用老百姓的民用船只把它围住