Ok. Do note that I'm using simple wrapper classes for the thread sync objects (prefix of e means event, cs means critical section). Also, index is the set in question.
In the main thread:
Code:
csIndex.enter();
eUpdate.set();
eUpdateResponse.query(INFINITE);
index.erase(index.find(si)); //si is always contained in the set
csIndex.leave();
eUpdateResponse.query(INFINITE);
In thread:
Code:
//This is all in a loop
DWORD res = WaitForMultipleObjects(count, events, FALSE, INFINITE);
if(res == WAIT_FAILED)
{
MessageBox(NULL, "Wait failed", "Error", MB_OK | MB_ICONSTOP);
return 1;
}
res -= WAIT_OBJECT_0;
if(res == 0) //Quit
{
break;
}
else if(res == 1) //eUpdate was set
{
eUpdateResponse.set();
delete[] events;
csIndex.enter();
eUpdateResponse.set();
count = index.size() + 2;
events = new HANDLE[count];
events[0] = quitEvent;
events[1] = eUpdate;
HANDLE* eIt = events + 2;
std::set<SockInfo*>::iterator iIt = index.begin();
for(; iIt != index.end(); ++iIt, ++eIt)
*eIt = (HANDLE)((*iIt)->notify); //Access violation here
csIndex.leave();
}
Also, (*iIt) always evaluates to a valid pointer, or at least should. There's a lot of extra stuff, since the events are part of a greater scheme of things, to sync. properly with other potential threads... but that's the gist of it.