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. _endthreadex()

_endthreadex()

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 3 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.
  • P Offline
    P Offline
    Programmer Anju
    wrote on last edited by
    #1

    I have an application that uses threads. The purpose of one thread is to Listen for any communication request from other machines. This has an infinite while loop. There have to be 2 stopping conditions for the same. One is when it receives a Stop boolean variable, it stops the whole application. The other condition I want to add is that if it sees a global boolean variable is set (which needs to be set by some other thread of the same application) it should end that particular listen thread only (not the whole application). If I use _endthreadex() how will the other thread form which the boolean variable was set know that the listen thread has actually ended? I was using TerminateThread() to end the Listen thread because it accepts the handle of the thread as an argument so that I was able to end the thread from some other thread but I see it is not cleaning up after Terminating the thread.

    T D 3 Replies Last reply
    0
    • P Programmer Anju

      I have an application that uses threads. The purpose of one thread is to Listen for any communication request from other machines. This has an infinite while loop. There have to be 2 stopping conditions for the same. One is when it receives a Stop boolean variable, it stops the whole application. The other condition I want to add is that if it sees a global boolean variable is set (which needs to be set by some other thread of the same application) it should end that particular listen thread only (not the whole application). If I use _endthreadex() how will the other thread form which the boolean variable was set know that the listen thread has actually ended? I was using TerminateThread() to end the Listen thread because it accepts the handle of the thread as an argument so that I was able to end the thread from some other thread but I see it is not cleaning up after Terminating the thread.

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

      Programmer Anju wrote:

      The other condition I want to add is that if it sees a global boolean variable is set (which needs to be set by some other thread of the same application) it should end that particular listen thread only (not the whole application). If I use _endthreadex() how will the other thread form which the boolean variable was set know that the listen thread has actually ended?

      program listen thread something line this   g_bEndListenThread=FALSE; while(1) {   if(g_bEndApplication==TRUE)    // End listen thread      return 0; or _endthreadex();     if(g_bEndListenThread==TRUE)    // End listen thread      return 0; or _endthreadex(); // Do normal functioning }

      "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
      • P Programmer Anju

        I have an application that uses threads. The purpose of one thread is to Listen for any communication request from other machines. This has an infinite while loop. There have to be 2 stopping conditions for the same. One is when it receives a Stop boolean variable, it stops the whole application. The other condition I want to add is that if it sees a global boolean variable is set (which needs to be set by some other thread of the same application) it should end that particular listen thread only (not the whole application). If I use _endthreadex() how will the other thread form which the boolean variable was set know that the listen thread has actually ended? I was using TerminateThread() to end the Listen thread because it accepts the handle of the thread as an argument so that I was able to end the thread from some other thread but I see it is not cleaning up after Terminating the thread.

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

        Programmer Anju wrote:

        The other condition I want to add is that if it sees a global boolean variable is set (which needs to be set by some other thread of the same application) it should end that particular listen thread only (not the whole application). If I use _endthreadex() how will the other thread form which the boolean variable was set know that the listen thread has actually ended?

        program listen thread something line this   g_bEndListenThread=FALSE; while(1) {   if(g_bEndApplication==TRUE)    // End listen thread      return 0; or _endthreadex();     if(g_bEndListenThread==TRUE)    // End listen thread      return 0; or _endthreadex(); // Dyour Thread functioning }

        "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
        • P Programmer Anju

          I have an application that uses threads. The purpose of one thread is to Listen for any communication request from other machines. This has an infinite while loop. There have to be 2 stopping conditions for the same. One is when it receives a Stop boolean variable, it stops the whole application. The other condition I want to add is that if it sees a global boolean variable is set (which needs to be set by some other thread of the same application) it should end that particular listen thread only (not the whole application). If I use _endthreadex() how will the other thread form which the boolean variable was set know that the listen thread has actually ended? I was using TerminateThread() to end the Listen thread because it accepts the handle of the thread as an argument so that I was able to end the thread from some other thread but I see it is not cleaning up after Terminating the thread.

          D Offline
          D Offline
          Daniel Lohmann
          wrote on last edited by
          #4

          If a thread or process terminates, the OS-internal thread/process object is set to signaled state - the state you can use to wait for with e.g. WaitForSingleObject(). So if hThread is your thread handle, the following would wait until the thread has actually terminated: WaitForSingleObject( hThread, INFINITE ) The point is that you might also use the waiting functions to test if an object (in this case the thread) is in signaled state (in this case has terminated) by just using 0 as the timeout value: if( WaitForSingleObject( hThread, 0 ) == WAIT_TIMEOUT ) { // not terminated yet } -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )

          T 1 Reply Last reply
          0
          • D Daniel Lohmann

            If a thread or process terminates, the OS-internal thread/process object is set to signaled state - the state you can use to wait for with e.g. WaitForSingleObject(). So if hThread is your thread handle, the following would wait until the thread has actually terminated: WaitForSingleObject( hThread, INFINITE ) The point is that you might also use the waiting functions to test if an object (in this case the thread) is in signaled state (in this case has terminated) by just using 0 as the timeout value: if( WaitForSingleObject( hThread, 0 ) == WAIT_TIMEOUT ) { // not terminated yet } -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )

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

            Daniel Lohmann wrote:

            WaitForSingleObject(). So if hThread is your thread handle, the following would wait until the thread has actually terminated: WaitForSingleObject( hThread, INFINITE ) The point is that you might also use the waiting functions to test if an object (in this case the thread) is in signaled state (in this case has terminated) by just using 0 as the timeout value:

            In call of TerminateProcess api, system will close the thread, without releasing any  of it memory and related stuff. there might be case the system hang indefinatly at the call of WaitForSingleObject api!

            "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