RE: Is this Multithread safe, or does it require Interloc ked access?

InterlockedExchangeAdd.

=====================
Mark Roddy


From: xxxxx@conexant.com [mailto:xxxxx@conexant.com]
Sent: Tuesday, November 09, 2004 2:54 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Is this Multithread safe, or does it require Interlocked
access?

I am using a global pointer here for ease of explanation, but it will end up
in some sort of class, or context structure.

Thread1, and Thread2 will execute simultaneously, in either a
hyperthreading, or “Dual Processing” environment. I.e., elements of
GlobalArray will be incremented by 2 threads simultaneously. Are there
cacheing issues, or synchronization issues here? Is the “Add” instruction
atomic? Or, do I need to grab some sort of spinlock, or use InterlockedXXX
instructions in thread1, and thread2?

Thanks,
James



char * GlobalArray[20];

Initialize()
{
// Set all elements of GlobalArray to 0.
ZeroArray(GlobalArray);

Launch(Thread1);
Launch(Thread2);

// Wait until Thread1 and 2 Complete.
wait();

// Check the value of GlobalArray is correct.
// GlobalArray[1] = 2, GlobalArray[2] = 4, GlobalArray[3] = 6 etc…

}

Thread1()
{
for(i=0; i<20; i++)
GlobalArray[i] += i;
}

Thread2()
{
for(i=0; i<20; i++)
GlobalArray[i] += i;
} —
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com