Critical section ?
From: Jason (yo_at_yo.com)
Date: 12/21/04
- Next message: Roy Fine: "Re: Critical section ?"
- Previous message: Rick Ruhl: "Re: accelerator calling member function twice"
- Next in thread: Roy Fine: "Re: Critical section ?"
- Reply: Roy Fine: "Re: Critical section ?"
- Reply: Michael K. O'Neill: "Re: Critical section ?"
- Reply: code_cold: "How to keep two window in same z order"
- Reply: Mihajlo Cvetanovic: "Re: Critical section ?"
- Reply: Naren: "RE: Critical section ?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 20 Dec 2004 19:00:51 -0500
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 and any alternative or better
answers?
Thanks.
Happy Holidays.
- Next message: Roy Fine: "Re: Critical section ?"
- Previous message: Rick Ruhl: "Re: accelerator calling member function twice"
- Next in thread: Roy Fine: "Re: Critical section ?"
- Reply: Roy Fine: "Re: Critical section ?"
- Reply: Michael K. O'Neill: "Re: Critical section ?"
- Reply: code_cold: "How to keep two window in same z order"
- Reply: Mihajlo Cvetanovic: "Re: Critical section ?"
- Reply: Naren: "RE: Critical section ?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|