thready
asked on
vector and threads
Hi Experts,
I want to have a bunch of threads that share a vector. If I keep a critical section around the vector at all places where it is accessed, am I ok?
i.e., I place a critical section around the size() call where the parent class that owns the vector is a GetSize
I place a critical section around code that adds items to the vector in the AddItem function
Is there anything else to watch out for?
Thanks,
Mike
I want to have a bunch of threads that share a vector. If I keep a critical section around the vector at all places where it is accessed, am I ok?
i.e., I place a critical section around the size() call where the parent class that owns the vector is a GetSize
I place a critical section around code that adds items to the vector in the AddItem function
Is there anything else to watch out for?
Thanks,
Mike
ASKER
ignore that last concern - I realized that size is a stack variable - not a member variable like I was thinking....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Gracias amigo
ASKER
int TaskRunner::GetNumberOfTas
{
EnterCriticalSection(&m_Qu
int nSize = m_TaskQueue.size();
LeaveCriticalSection(&m_Qu
// RIGHT HERE - SIZE MIGHT BE INCORRECT - ANOTHER THREAD MAY HAVE COME IN AND CHANGED SIZE
// JUST BEFORE I GOT TO RETURN IT. HOW DO I FIX THIS?
return nSize;
}