Hello, everyone!

I have a problem I don't know how to fix.
I need to create a few threads in a loop sending different arguments in there. Here is a simple version of my code:

for(i = 0; i < lSize; i++)
{
rsPtr = (CEntryTable*)tableArray.GetAt(i);
rs = *rsPtr;
arglist.pRs = pRs;
arglist.pCn = pCn;
arglist.rs = rs;
CreateThread(NULL, 0, BounceProc, (void*)&arglist, 0, NULL);
}




I have 3 entries, so BounceProc is supposed to be called 3 times each time with different arguments. But in reality it receives the last entry all 3 times.I understand it happens because the loop executes too fast, it worked when I put Sleep() after CreateThread(). Is there any other way to solve this problem? I tryed everything I could think of, nothing else worked.

Any ideas?

Thanks,

Irina.