PDA

View Full Version : bad ONLINEDATA usage ?


Mouton
10-17-2003, 10:51 PM
What's wrong with this code ?
It appears to work correctly, until you try to run multiple threads that does that... Then, it makes io (.14 and probably earlier) crash (probably when 2 threads do that at the exact same time).

I know it's this code that makes it crash cause if i comment the sendmessage, it doesn't crash anymore.

int iPos = 0, nPos = 0, Users = 0;
while (nPos != -1 && Users < 1000 ) {
// Initial setup for DC_GET_ONLINEDATA
lpMessage->dwIdentifier = DC_GET_ONLINEDATA;
LPDC_ONLINEDATA pOnlineData = (LPDC_ONLINEDATA)lpMessage->lpContext;
pOnlineData->iOffset = nPos;
pOnlineData->dwSharedMemorySize = sizeof(DC_MESSAGE) + sizeof(DC_ONLINEDATA) + (_MAX_PATH + 1) * 2;

// Send Message
dwReturn = SendMessage(hIoFTPD, WM_SHMEM, NULL, (LPARAM)hMemory);
if (!dwReturn) {
// Wait until processed (5 secs)
if (WaitForSingleObject(hEvent, 5000) == WAIT_TIMEOUT) break;

nPos = pOnlineData->iOffset;
if (iPos>=nPos || nPos == 1024)
break;

Users++;
iPos = nPos;
}
}

darkone
10-18-2003, 05:29 AM
Can you create me some simple binary that does it when executed from command line.. (might be that there's something wrong with the datacopy command queueing.. as i've only allowed 2worker threads to execute datacopy commands concurrently [special queue for those])

darkone
10-18-2003, 05:31 AM
Also, use asynchronous postmessage instead of sendmessage.. it's somewhat faster, and since you don't need to worry about wheter message gets through or not - it's optimal for the purpose.

darkone
10-18-2003, 05:50 AM
Also.. I'm not sure wheter 5secs is enough or not :)

Mouton
10-18-2003, 08:00 AM
still crash with PostMessage and 10s wait...

I'll get u a little .exe

darkone
10-18-2003, 08:13 AM
Create me that test app, and i'll give it a spin under debugger... propably something really simple that i've missed out (also check wheter your waitforsingleevent returns WAIT_TIMEOUT.. you never know :))

Mouton
10-18-2003, 08:45 AM
[Pre]
stor = EXEC "D:\Visual Studio Projects\testDC\Debug\testDC.exe"

It crash io when i use it there. When i run it from command-line, i can spawn 10 instances at the same time, it still works ok.

But if i put it in Pre Stor, and i simulate a race of 8 users (30x5mb files), it crash io.

darkone
10-18-2003, 09:41 AM
Ok.. found it, if all threads are executing scripts that require datacopy - datacopy will time-out, and once you exit your process - crash will occur, as you have already freed the memory area that datacopy tries to process. Threading is fun, isn't it?

Sounds like I have to do minor change in datacopy structure; DC_MESSAGE + add specific datacopy threads :/ Expect to see fix sometime tomorrow

Mouton
10-18-2003, 11:32 AM
thx very much :)