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. Flow is not passing in a worker thread

Flow is not passing in a worker thread

Scheduled Pinned Locked Moved C / C++ / MFC
helpjsontutorialquestion
9 Posts 3 Posters 1 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.
  • N Offline
    N Offline
    neha agarwal27
    wrote on last edited by
    #1

    I have made a sdi application, in that i have made a worker thread(in main application class) in that i have used some api's. Now my problem is in some case a api is not passing the flow of control. In this case after 10 seconds i want to display a message and break the thread. I tried to use timer through SetTimer method but it was not applicaple because WM_TIMER message is not present.Now, how to solve this problem? Can anybody help me in this. Thanks in advance

    K C 2 Replies Last reply
    0
    • N neha agarwal27

      I have made a sdi application, in that i have made a worker thread(in main application class) in that i have used some api's. Now my problem is in some case a api is not passing the flow of control. In this case after 10 seconds i want to display a message and break the thread. I tried to use timer through SetTimer method but it was not applicaple because WM_TIMER message is not present.Now, how to solve this problem? Can anybody help me in this. Thanks in advance

      K Offline
      K Offline
      Karismatic
      wrote on last edited by
      #2

      Hey, You can use void sleep( long millis ) instead of using timer

      Regards, Pankaj Sachdeva There is no future lies in any job but future lies in the person who holds the job

      1 Reply Last reply
      0
      • N neha agarwal27

        I have made a sdi application, in that i have made a worker thread(in main application class) in that i have used some api's. Now my problem is in some case a api is not passing the flow of control. In this case after 10 seconds i want to display a message and break the thread. I tried to use timer through SetTimer method but it was not applicaple because WM_TIMER message is not present.Now, how to solve this problem? Can anybody help me in this. Thanks in advance

        C Offline
        C Offline
        chandu004
        wrote on last edited by
        #3

        neha.agarwal27 wrote:

        Now my problem is in some case a api is not passing the flow of control

        do you mean that, your control flow is not coming out of your api? if that is so, then, as you said, timer is not working, you can initiate another thread and do your termination there after 10 seconds. any more clarifications?

        Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.

        N 1 Reply Last reply
        0
        • C chandu004

          neha.agarwal27 wrote:

          Now my problem is in some case a api is not passing the flow of control

          do you mean that, your control flow is not coming out of your api? if that is so, then, as you said, timer is not working, you can initiate another thread and do your termination there after 10 seconds. any more clarifications?

          Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.

          N Offline
          N Offline
          neha agarwal27
          wrote on last edited by
          #4

          can you explain me this through an example. I am not getting where to start a thread and how to apply your procedure

          C 1 Reply Last reply
          0
          • N neha agarwal27

            can you explain me this through an example. I am not getting where to start a thread and how to apply your procedure

            C Offline
            C Offline
            chandu004
            wrote on last edited by
            #5

            say your thread 1 is like this. thread1 { .... .... .... .... api1(); .... .... .... }if you feel that some times your control is not coming out of api1. right? so, take a global variable, say flag=0; before api1, make flag=1; and after api1 make it 0; take another thread, say, thread2() { int counter=0; while(1) { Sleep(1000);//1 second if(flag==1) { counter++; if(counter>10) terminate thread 1. } if (flag==0) { counter=0; } } } } }

            neha.agarwal27 wrote:

            I am not getting where to start a thread and how to apply your procedure

            start it just after your main thread creation.

            Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.

            N 1 Reply Last reply
            0
            • C chandu004

              say your thread 1 is like this. thread1 { .... .... .... .... api1(); .... .... .... }if you feel that some times your control is not coming out of api1. right? so, take a global variable, say flag=0; before api1, make flag=1; and after api1 make it 0; take another thread, say, thread2() { int counter=0; while(1) { Sleep(1000);//1 second if(flag==1) { counter++; if(counter>10) terminate thread 1. } if (flag==0) { counter=0; } } } } }

              neha.agarwal27 wrote:

              I am not getting where to start a thread and how to apply your procedure

              start it just after your main thread creation.

              Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.

              N Offline
              N Offline
              neha agarwal27
              wrote on last edited by
              #6

              your given code is working fine but now the problem is i am starting various number of same threads together(for example if i have to find html code of 20 websites same thread will be run together for 20 websites and i am synchronising them using critical section). so if i end my 1st thread in 2nd thread all processing will stop at once and i will not get output of left sites....So how to deal with it.

              C 2 Replies Last reply
              0
              • N neha agarwal27

                your given code is working fine but now the problem is i am starting various number of same threads together(for example if i have to find html code of 20 websites same thread will be run together for 20 websites and i am synchronising them using critical section). so if i end my 1st thread in 2nd thread all processing will stop at once and i will not get output of left sites....So how to deal with it.

                C Offline
                C Offline
                chandu004
                wrote on last edited by
                #7

                yah, got your problem. then you must change your architecture, in such a way, that, the timeout monitor thread is not common for all the threads. so implement as follows. thread1()//this thread may be having somany instances { create thread2();//which monitors the thread 1 for the timeout value. ------- ------ -------- flag=1; api1; flag=0; -------- } thread2() { you try to frame this logic. } here, for each thread1, a child thread(thread2) is created, which monitors its parent's(thread1's) timeout, and kills it if it is not responding in a specified timeout, and also terminates itself.

                Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.

                1 Reply Last reply
                0
                • N neha agarwal27

                  your given code is working fine but now the problem is i am starting various number of same threads together(for example if i have to find html code of 20 websites same thread will be run together for 20 websites and i am synchronising them using critical section). so if i end my 1st thread in 2nd thread all processing will stop at once and i will not get output of left sites....So how to deal with it.

                  C Offline
                  C Offline
                  chandu004
                  wrote on last edited by
                  #8

                  got it?

                  Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.

                  N 1 Reply Last reply
                  0
                  • C chandu004

                    got it?

                    Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.

                    N Offline
                    N Offline
                    neha agarwal27
                    wrote on last edited by
                    #9

                    i am still trying the method problem is not solved yet...

                    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