Critical section ?
From: James (you_at_yo.net)
Date: 12/20/04
- Next message: Anand Hariharan: "Meaning of this declaration?"
- Previous message: Mike Wahler: "Re: pesky Pointers !!"
- Next in thread: Paul F. Johnson: "Re: Critical section ?"
- Reply: Paul F. Johnson: "Re: Critical section ?"
- Reply: Andrey Tarasevich: "Re: [OT] Critical section ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 20 Dec 2004 21:43:59 GMT
I recently was asked to answer this
int g_nNums[100]
DWORD WINAPI Thread(LPVOID lpvParams)
{
int iIndex = some value;
EnterCriticalSection(g_CriticalSection);
if( g_Nums[nIndex] < MIN_VAL)
IncrementIndex(iIndex);
else
g_nNums[iIndex] = MIN_VAL;
LeaveCriticalSecton(&g_CriticalSection);
return 0;
}
void IncrementIndex(int iIndex)
{
...
g_nNums[nIndex++];
...
}
How can IncrementIndex be written so that it is thread safe and won't
deadlock?
I answered that I would wrap it in a critical seciton or a mutex. What are
the potential problems with that answer ?
Thanks.
- Next message: Anand Hariharan: "Meaning of this declaration?"
- Previous message: Mike Wahler: "Re: pesky Pointers !!"
- Next in thread: Paul F. Johnson: "Re: Critical section ?"
- Reply: Paul F. Johnson: "Re: Critical section ?"
- Reply: Andrey Tarasevich: "Re: [OT] Critical section ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|