Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. can i debug multi threading application?

can i debug multi threading application?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondebuggingtutorial
20 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T toxcct

    hum, i'd say go ahead, as we're on the forum for it... if you don't ask, we won't be able to answer. but if the question is not respecting the guidelines, be ready to be flamed ! lol


    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

    A Offline
    A Offline
    amitmistry_petlad
    wrote on last edited by
    #8

    Thank you sir! sir when I debug my application. As I debug, all the handles created properly for threads and I have pass the structure pointer (paramters) but value passed through the pointer is same at each call . what should i do? should I have to take array of pointers for struct varibale? -- modified at 9:50 Monday 7th May, 2007

    "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

    T 1 Reply Last reply
    0
    • A amitmistry_petlad

      Thank you sir! sir when I debug my application. As I debug, all the handles created properly for threads and I have pass the structure pointer (paramters) but value passed through the pointer is same at each call . what should i do? should I have to take array of pointers for struct varibale? -- modified at 9:50 Monday 7th May, 2007

      "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #9

      i'm not sure i get your english very well... can you show a piece of code that reproduces the problem ?


      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      A 1 Reply Last reply
      0
      • T toxcct

        i'm not sure i get your english very well... can you show a piece of code that reproduces the problem ?


        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        A Offline
        A Offline
        amitmistry_petlad
        wrote on last edited by
        #10

        sorry for my english, better with snippest, for(int i=0;i<3;i++) struct argument_list *l ; l=(argument_list *)malloc(sizeof(argument_list)); l->pszInFile=bufferwithpath; //each time got the same values in the thread function. l->pszOutFil=w_Output; //time got the same values in the thread function. l->_ProtectSet=_ProtectSet; l->hList=hList; strcpy(l->Host,HOST); l->hwndEncrypt=hwndEncrypt; l->hWndinoutfiledir=hWndinoutfiledir; l->hwndParent=hDlg; strcpy(l->InitPackageRequest,sINIT_PACKAGE_RESPONSE.c_str()); l->Port=PORT; strcpy(l->ScriptFile,COMMUNICATOR_SCRIPT_FILE_PATH); strcpy(l->UserID,UserID.c_str()); //hThread[i]=(HANDLE)_beginthreadex(NULL, 0, &Thread ,l,NULL, &threadID); hThread[i]=(HANDLE)_beginthread(&Thread ,0 , l ); //WaitForSingleObject(hThread,INFINITE); } WaitForMultipleObjects(3, hThread, FALSE, INFINITE); below is thread function. void Thread(void* pArguments ) { if( pArguments == NULL ) { MessageBox( NULL , _T("Problem in thread") , NULL , IDOK ) ; } HRESULT hr=NULL; struct argument_list *Lparam= (argument_list *)pArguments ; Package pkg; static int threadID; threadID++; **{ hr=pkg.EncodeMediaContent(Lparam->pszInFile,Lparam->pszOutFil,Lparam->hwndParent,Lparam->Host,Lparam->UserID,Lparam->InitPackageRequest,Lparam->ScriptFile,Lparam->Port,Lparam->hList,Lparam->_ProtectSet,Lparam->hWndinoutfiledir,Lparam->hwndEncrypt); }** //the above function call 3(becoz of three threads) times with same value and when i debug the above function it will hang afterward. if(hr==S_OK) { MessageBox(0,L"thread gone finished" ,L"therad",0); _endthreadex( 0 ); } threadID--; }

        "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

        M 1 Reply Last reply
        0
        • A amitmistry_petlad

          sorry for my english, better with snippest, for(int i=0;i<3;i++) struct argument_list *l ; l=(argument_list *)malloc(sizeof(argument_list)); l->pszInFile=bufferwithpath; //each time got the same values in the thread function. l->pszOutFil=w_Output; //time got the same values in the thread function. l->_ProtectSet=_ProtectSet; l->hList=hList; strcpy(l->Host,HOST); l->hwndEncrypt=hwndEncrypt; l->hWndinoutfiledir=hWndinoutfiledir; l->hwndParent=hDlg; strcpy(l->InitPackageRequest,sINIT_PACKAGE_RESPONSE.c_str()); l->Port=PORT; strcpy(l->ScriptFile,COMMUNICATOR_SCRIPT_FILE_PATH); strcpy(l->UserID,UserID.c_str()); //hThread[i]=(HANDLE)_beginthreadex(NULL, 0, &Thread ,l,NULL, &threadID); hThread[i]=(HANDLE)_beginthread(&Thread ,0 , l ); //WaitForSingleObject(hThread,INFINITE); } WaitForMultipleObjects(3, hThread, FALSE, INFINITE); below is thread function. void Thread(void* pArguments ) { if( pArguments == NULL ) { MessageBox( NULL , _T("Problem in thread") , NULL , IDOK ) ; } HRESULT hr=NULL; struct argument_list *Lparam= (argument_list *)pArguments ; Package pkg; static int threadID; threadID++; **{ hr=pkg.EncodeMediaContent(Lparam->pszInFile,Lparam->pszOutFil,Lparam->hwndParent,Lparam->Host,Lparam->UserID,Lparam->InitPackageRequest,Lparam->ScriptFile,Lparam->Port,Lparam->hList,Lparam->_ProtectSet,Lparam->hWndinoutfiledir,Lparam->hwndEncrypt); }** //the above function call 3(becoz of three threads) times with same value and when i debug the above function it will hang afterward. if(hr==S_OK) { MessageBox(0,L"thread gone finished" ,L"therad",0); _endthreadex( 0 ); } threadID--; }

          "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #11

          amitmistry_petlad wrote:

          l->pszInFile=bufferwithpath; //each time got the same values in the thread function. l->pszOutFil=w_Output; //time got the same values in the thread function.

          If you put the same values in your argument_list structs, then you'll get the same values in every thread proc. Unless something is missing in the code you posted, I can't see you putting anything different in the 3 structs. Mark

          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

          A 1 Reply Last reply
          0
          • R Rajesh R Subramanian

            amitmistry_petlad wrote:

            hi !

            Hi!

            amitmistry_petlad wrote:

            sorry to ask a question on thread.

            That's okay.

            amitmistry_petlad wrote:

            can I debug multithreading application?

            Yo!

            "The difficulty lies, not in the new ideas, but in escaping from the old ones." -- John Maynard Keyes, 1936

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #12

            Your answer is exactly to question very similar :laugh: but whats meaning of "Yo"?


            WhiteSky


            S 1 Reply Last reply
            0
            • M Mark Salsbery

              amitmistry_petlad wrote:

              l->pszInFile=bufferwithpath; //each time got the same values in the thread function. l->pszOutFil=w_Output; //time got the same values in the thread function.

              If you put the same values in your argument_list structs, then you'll get the same values in every thread proc. Unless something is missing in the code you posted, I can't see you putting anything different in the 3 structs. Mark

              "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

              A Offline
              A Offline
              amitmistry_petlad
              wrote on last edited by
              #13

              sir, I have made the walkthru but it is some what long so I afrid to put it in the fouram.

              "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

              M 1 Reply Last reply
              0
              • A amitmistry_petlad

                sir, I have made the walkthru but it is some what long so I afrid to put it in the fouram.

                "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #14

                OK. But you show this in your code... l->pszInFile=bufferwithpath; //each time got the same values in the thread function. l->pszOutFil=w_Output; //time got the same values in the thread function. If these values are the same all three iterations through the loop, and you don't expect them to be the same, then that's the problem. My point is, you don't show where those values come from in your code so we can't help you with that part :) Mark

                "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                A 1 Reply Last reply
                0
                • M Mark Salsbery

                  OK. But you show this in your code... l->pszInFile=bufferwithpath; //each time got the same values in the thread function. l->pszOutFil=w_Output; //time got the same values in the thread function. If these values are the same all three iterations through the loop, and you don't expect them to be the same, then that's the problem. My point is, you don't show where those values come from in your code so we can't help you with that part :) Mark

                  "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                  A Offline
                  A Offline
                  amitmistry_petlad
                  wrote on last edited by
                  #15

                  Mark Salsbery wrote:

                  l->pszInFile=bufferwithpath; //each time got the same values in the thread function. l->pszOutFil=w_Output; //time got the same values in the thread function.

                  Dear mark, for the above I got the values different but when the therad started and go in the thread function there is one function which I shown bold that shown me the same value each time and call that function with same value . suppose. there are two thread and both call the function Thread . in loop when the values shown different in structure pointer l but when thread call each it get the last value of listview. it means first values for each thread called in the structure pointer l. how can i handle that one? can you give me some guideline.Please ... :sigh:

                  "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

                  M 1 Reply Last reply
                  0
                  • H Hamid Taebi

                    Your answer is exactly to question very similar :laugh: but whats meaning of "Yo"?


                    WhiteSky


                    S Offline
                    S Offline
                    super_ttd
                    wrote on last edited by
                    #16

                    by "Yo", he meant "Ya" with a mouth getting closed... get what i mean ? ;)

                    1 Reply Last reply
                    0
                    • A amitmistry_petlad

                      Mark Salsbery wrote:

                      l->pszInFile=bufferwithpath; //each time got the same values in the thread function. l->pszOutFil=w_Output; //time got the same values in the thread function.

                      Dear mark, for the above I got the values different but when the therad started and go in the thread function there is one function which I shown bold that shown me the same value each time and call that function with same value . suppose. there are two thread and both call the function Thread . in loop when the values shown different in structure pointer l but when thread call each it get the last value of listview. it means first values for each thread called in the structure pointer l. how can i handle that one? can you give me some guideline.Please ... :sigh:

                      "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #17

                      amitmistry_petlad wrote:

                      there are two thread and both call the function Thread

                      I'm not sure what you mean here. Thread should not be called by anything. It is a threadproc and the code in it should run when you call _beginthreadex().

                      amitmistry_petlad wrote:

                      but when thread call each it get the last value of listview.

                      If you are passing a structure pointer into the thread then you should be getting values from there. Why would multiple threads be accessing a listview? This is something you have to debug. Get it working with one thread then try multiple threads. I don't know what's going on in the function you showed in bold, but everything you do in there needs to be thread safe - any objects that ca't be accessed simultaneously need to be protected with thread synchronization objects of some kind. Mark

                      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                      A 1 Reply Last reply
                      0
                      • M Mark Salsbery

                        amitmistry_petlad wrote:

                        there are two thread and both call the function Thread

                        I'm not sure what you mean here. Thread should not be called by anything. It is a threadproc and the code in it should run when you call _beginthreadex().

                        amitmistry_petlad wrote:

                        but when thread call each it get the last value of listview.

                        If you are passing a structure pointer into the thread then you should be getting values from there. Why would multiple threads be accessing a listview? This is something you have to debug. Get it working with one thread then try multiple threads. I don't know what's going on in the function you showed in bold, but everything you do in there needs to be thread safe - any objects that ca't be accessed simultaneously need to be protected with thread synchronization objects of some kind. Mark

                        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                        A Offline
                        A Offline
                        amitmistry_petlad
                        wrote on last edited by
                        #18

                        Dear mark yesterday I have found the solution for that.I have used some handles. that handle sendmessage to the main window but due to the waitformultipleobject stoping the message processing so I am try to implement MsgWaitForMultipleObjects. Thanks Nave he given me guideline.But can you give me the exact position where should I have call this function? In Thread function or in mainthread where I had create my worker thread where ? where ? where? :)

                        "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

                        T 1 Reply Last reply
                        0
                        • A amitmistry_petlad

                          Dear mark yesterday I have found the solution for that.I have used some handles. that handle sendmessage to the main window but due to the waitformultipleobject stoping the message processing so I am try to implement MsgWaitForMultipleObjects. Thanks Nave he given me guideline.But can you give me the exact position where should I have call this function? In Thread function or in mainthread where I had create my worker thread where ? where ? where? :)

                          "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

                          T Offline
                          T Offline
                          ThatsAlok
                          wrote on last edited by
                          #19

                          amitmistry_petlad wrote:

                          n Thread function or in mainthread where I had create my worker thread where ? where ? where?

                          isn't break point working!

                          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                          cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                          1 Reply Last reply
                          0
                          • CPalliniC CPallini

                            Why not? :)

                            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                            T Offline
                            T Offline
                            ThatsAlok
                            wrote on last edited by
                            #20

                            CPallini wrote:

                            Why not?

                            will try [:)]

                            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                            cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups