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. problem in THREAD TERMINATE

problem in THREAD TERMINATE

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomhelp
4 Posts 4 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.
  • K Offline
    K Offline
    Khatri Mitesh
    wrote on last edited by
    #1

    Hi, All I am Creating a Thread Using CreateThread() Function and in it's procedure I am performing my Task But on a Specific Condition i want Terminate it and for it I am using TerminateThread() Function but it Return 0 Which indicate Failure as per msdn it require that my CreateThread() handle must have THREAD_TERMINATE access How Can i Set it? Thanks Mitesh

    ~Khatri Mitesh khatrimitesh@hotmail.com Bikaner (Rajasthan) INDIA

    C J CPalliniC 3 Replies Last reply
    0
    • K Khatri Mitesh

      Hi, All I am Creating a Thread Using CreateThread() Function and in it's procedure I am performing my Task But on a Specific Condition i want Terminate it and for it I am using TerminateThread() Function but it Return 0 Which indicate Failure as per msdn it require that my CreateThread() handle must have THREAD_TERMINATE access How Can i Set it? Thanks Mitesh

      ~Khatri Mitesh khatrimitesh@hotmail.com Bikaner (Rajasthan) INDIA

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      ~Khatri Mitesh~ wrote:

      But on a Specific Condition i want Terminate it and for it I am using TerminateThread() Function

      You should never end a thread this way. A much better approach is to simply set a flag that is checked regularly by your thread. When the flag is set, the thread knows it has to end and it will do it naturally (instead of being killed in the middle of something).

      Cédric Moonen Software developer
      Charting control [v1.5] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • K Khatri Mitesh

        Hi, All I am Creating a Thread Using CreateThread() Function and in it's procedure I am performing my Task But on a Specific Condition i want Terminate it and for it I am using TerminateThread() Function but it Return 0 Which indicate Failure as per msdn it require that my CreateThread() handle must have THREAD_TERMINATE access How Can i Set it? Thanks Mitesh

        ~Khatri Mitesh khatrimitesh@hotmail.com Bikaner (Rajasthan) INDIA

        J Offline
        J Offline
        Jijo Raj
        wrote on last edited by
        #3

        You should never use TerminateThread(), since it can easly cause deadlock in your application. Check this[^] and the documentation from MSDN below. MSDN: TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems: Well, you could use event object to implement same behavior. Well, in the mean while i found this thread[^] also. May be useful to you. Regards, Jijo.

        _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

        1 Reply Last reply
        0
        • K Khatri Mitesh

          Hi, All I am Creating a Thread Using CreateThread() Function and in it's procedure I am performing my Task But on a Specific Condition i want Terminate it and for it I am using TerminateThread() Function but it Return 0 Which indicate Failure as per msdn it require that my CreateThread() handle must have THREAD_TERMINATE access How Can i Set it? Thanks Mitesh

          ~Khatri Mitesh khatrimitesh@hotmail.com Bikaner (Rajasthan) INDIA

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          As previous replies stated, you should never call TerminateThread (since there are better ways to handle your scenario). Anyway, if you're stuck on your (bad) idea, what about reading the documentation [^]?

          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.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          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