Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi,
I am new to multithreading. I have made a dll using shared dll using MFC program using a tutorial, after it I changed its settings to statically linked so i can used to call its functions in a multithread. Now when I am calling this dll functions from anbother project I am getting an error, the first thread stops working at soon as the second thread is called upon. My functions and thread definitions are as follows, I have compiled and copy the updated version of the dll file in my new project.

C++
  CWinThread      *m_thread;
  CWinThread      *m_thread1;


CdecoderD3D9App *decoder_object_1 = new CdecoderD3D9App(460, 1);
m_thread = AfxBeginThread(MainTread, decoder_object_1);

CdecoderD3D9App *decoder_object_2 = new CdecoderD3D9App(460, 2);
m_thread1 = AfxBeginThread(MainTread1, decoder_object_2);


My functions are as follows for both of the threads,

C++
UINT Ctesting_projectDlg::MainTread(LPVOID pParam)

{
    clock_t t1, t2;
    t1 = clock(); 
    CdecoderD3D9App *decoder_object_1 = (CdecoderD3D9App *)pParam;
    char *video_source = "my_movie.mp4";



    decoder_object_1->InitInstance();

    decoder_object_1->run_program(video_source);


    t2 = clock(); 
    float diff = (((float)t2 - (float)t1) / 1000000.0F ) * 10;


    return 0;
}


UINT Ctesting_projectDlg::MainTread1(LPVOID pParam)

{
    clock_t t1, t2;
    t1 = clock(); 
    CdecoderD3D9App *decoder_object_3 = (CdecoderD3D9App *)pParam;

    char *video_source = "my_movie.m2v";



    decoder_object_3->InitInstance();




    decoder_object_3->run_program(video_source);
    t2 = clock(); 
    float diff = (((float)t2 - (float)t1) / 1000000.0F ) * 10;

    return 0;
}


Now when I am calling this function the second threads kind of exit the first thread as soon as it is called. Does that mean i have to make a new dll project with statically linked items or any other problem ?
Also the dll class is basically a modified version of DecoderD3D9 CUDA example, in which CWinApp inheritance is removed also so now it is just a simple independant class.
My dll file properties are as:
C++
Configuration Type -> Dynamic Library(.dll)
Use of MFC -> Use MFC in a static library
Character set -> Use Multi-Byte Character Set
Posted
Comments
nv3 10-Sep-13 8:19am    
Whether your DLL is statically or dynamically linked has nothing to do with its multi-threading behavior. If your decoder object is not thread-safe it doesn't help to put it into a statically linked library. Does this entire thing work as long as you have linked it dynamically -- all other things the same?
nothan 10-Sep-13 8:33am    
yeah it works fully if i am running one thread but as soon as i start two threads it is still running only one thread the other one stops working as soon as the second one is being called.
pasztorpisti 10-Sep-13 8:35am    
One thing is almost sure: the bug is probably not in the code you have posted.
nothan 10-Sep-13 8:39am    
But this is the only code present in my application I am using to call upon. Is it possible that the CUDA dll project is not made correctly ?
But its also multithreaded so it should be able to call multithreads.
pasztorpisti 10-Sep-13 8:44am    
This is not the full source code of your program for sure. There can be tons of bugs anywhere else. Also CdecoderD3D9App must support multiple threads, read its documentation about multithreading. Calling functions from threads without reading the documentation of the used functions/classes is a suicide.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900