Please tell me what is wrong with my threading!!!

Posted by kiddo on Stack Overflow See other posts from Stack Overflow or by kiddo
Published on 2010-05-11T08:07:32Z Indexed on 2010/05/11 8:14 UTC
Read the original article Hit count: 164

Filed under:
|

I have a function where I will compress a bunch of files into a single compressed file..it is taking a long time(to compress),so I tried implementing threading in my application..Say if I have 20 files for compression,I separated that as 5*4=20,inorder to do that I have separate variables(which are used for compression) for all 4 threads in order to avoid locks and I will wait until the 4 thread finishes..Now..the threads are working but i see no improvement in their performance..normally it will take 1 min for 20 files(for example) after implementing threading ...there is only 5 or 3 sec difference., sometimes the same. here i will show the code for 1 thread(so it is for other3 threads)

//main thread   
    myClassObject->thread1 = AfxBeginThread((AFX_THREADPROC)MyThreadFunction1,myClassObject);
    ....

    HANDLE threadHandles[4];
    threadHandles[0] = myClassObject->thread1->m_hThread;
    ....

    WaitForSingleObject(myClassObject->thread1->m_hThread,INFINITE);

UINT MyThreadFunction(LPARAM lparam)
{

    CMerger* myClassObject = (CMerger*)lparam;
    CString outputPath = myClassObject->compressedFilePath.GetAt(0);//contains the o/p path
    wchar_t* compressInputData[] = {myClassObject->thread1outPath,
                    COMPRESS,(wchar_t*)(LPCTSTR)(outputPath)};
    HINSTANCE loadmyDll;
    loadmydll = LoadLibrary(myClassObject->thread1outPath);
    fp_Decompress callCompressAction = NULL;
    int getCompressResult=0;
    myClassObject->MyCompressFunction(compressInputData,loadClient7zdll,callCompressAction,myClassObject->thread1outPath,
                    getCompressResult,minIndex,myClassObject->firstThread,myClassObject);
    return 0;
}

© Stack Overflow or respective owner

Related posts about multithreading

Related posts about mfc