Sharing an object between threads
Posted
by Dave18
on Stack Overflow
See other posts from Stack Overflow
or by Dave18
Published on 2010-06-06T08:11:11Z
Indexed on
2010/06/06
8:12 UTC
Read the original article
Hit count: 325
How would you set the object data that is shared between threads and needs to be updated once after the complete cycle of (say) two threads in busy loop?
CRITICAL_SECTION critical_section_;
int value; //needs to be updated once after the cycle of any number of threads running in busy loop
void ThreadsFunction(int i)
{
while (true)
{
EnterCriticalSection(&critical_section_);
/* Lines of Code */
LeaveCriticalSection(&critical_section_);
}
}
© Stack Overflow or respective owner