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. Threading

Threading

Scheduled Pinned Locked Moved C / C++ / MFC
helplearning
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.
  • U Offline
    U Offline
    Umair Ahmad khan
    wrote on last edited by
    #1

    I am having a little problem handling Threads. Problem is, there is a Thread that i want to Terminate when Destructor of a Class called. Thread function is Using some functions of that class. I have done bit reading on Threading(still learning concepts etc) and about terminating a thread the way i want to use is AfxEndThread. it must be called within the thread that has to be terminated. or can it be called outside that thread also. or is there any way to terminate that thread from outside by some other thread. pThread = AfxBeginThread(run,&nCount,THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); pThread->m_bAutoDelete=false; pThread->ResumeThread(); thats how i am initializing the Thread. Now what if i just delete pThread object will this terminate the thread. ************************** bit more detail... above code is placed in the constructor of same class .. now another class when makes object of this class thread should start working and when it delets the object thread must also be end. I am getting some assertion error while some where in terminating the thread. and don't know where

    U M D 3 Replies Last reply
    0
    • U Umair Ahmad khan

      I am having a little problem handling Threads. Problem is, there is a Thread that i want to Terminate when Destructor of a Class called. Thread function is Using some functions of that class. I have done bit reading on Threading(still learning concepts etc) and about terminating a thread the way i want to use is AfxEndThread. it must be called within the thread that has to be terminated. or can it be called outside that thread also. or is there any way to terminate that thread from outside by some other thread. pThread = AfxBeginThread(run,&nCount,THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); pThread->m_bAutoDelete=false; pThread->ResumeThread(); thats how i am initializing the Thread. Now what if i just delete pThread object will this terminate the thread. ************************** bit more detail... above code is placed in the constructor of same class .. now another class when makes object of this class thread should start working and when it delets the object thread must also be end. I am getting some assertion error while some where in terminating the thread. and don't know where

      U Offline
      U Offline
      Umair Ahmad khan
      wrote on last edited by
      #2

      well the Error I am getting is Debug Assertion Failed. File: WinCore.cpp Line: 1002 well is this problem of my thread. :s

      1 Reply Last reply
      0
      • U Umair Ahmad khan

        I am having a little problem handling Threads. Problem is, there is a Thread that i want to Terminate when Destructor of a Class called. Thread function is Using some functions of that class. I have done bit reading on Threading(still learning concepts etc) and about terminating a thread the way i want to use is AfxEndThread. it must be called within the thread that has to be terminated. or can it be called outside that thread also. or is there any way to terminate that thread from outside by some other thread. pThread = AfxBeginThread(run,&nCount,THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); pThread->m_bAutoDelete=false; pThread->ResumeThread(); thats how i am initializing the Thread. Now what if i just delete pThread object will this terminate the thread. ************************** bit more detail... above code is placed in the constructor of same class .. now another class when makes object of this class thread should start working and when it delets the object thread must also be end. I am getting some assertion error while some where in terminating the thread. and don't know where

        M Offline
        M Offline
        meinhard_risch
        wrote on last edited by
        #3

        Hallo, I had a simmilar problem and I solved the problem by using a shared bool var. if the var is set to true from outside the thread terminats its self. Try to use it. Meinhard

        U 1 Reply Last reply
        0
        • M meinhard_risch

          Hallo, I had a simmilar problem and I solved the problem by using a shared bool var. if the var is set to true from outside the thread terminats its self. Try to use it. Meinhard

          U Offline
          U Offline
          Umair Ahmad khan
          wrote on last edited by
          #4

          thanks for your reply well my problem solved the problem was i was trying to access a class function when there was no class object .. i mean with empty pointer :D .. and there was one more problem that if i start the thread again before it ends up or the class object is destroyed this create problem because thread is still using the class and class object was deleted .. so i make 2 boolean when destructor call comes one goes to false and destructor goes in an empty loop and this false boolean tell thread ok end now. before thread ends it false the other one too .. to tell destructor ok i m finish now .. so destructor comes out of loop and object destroy. it is something like syncronization .. or what ever :) but problem is solved

          1 Reply Last reply
          0
          • U Umair Ahmad khan

            I am having a little problem handling Threads. Problem is, there is a Thread that i want to Terminate when Destructor of a Class called. Thread function is Using some functions of that class. I have done bit reading on Threading(still learning concepts etc) and about terminating a thread the way i want to use is AfxEndThread. it must be called within the thread that has to be terminated. or can it be called outside that thread also. or is there any way to terminate that thread from outside by some other thread. pThread = AfxBeginThread(run,&nCount,THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); pThread->m_bAutoDelete=false; pThread->ResumeThread(); thats how i am initializing the Thread. Now what if i just delete pThread object will this terminate the thread. ************************** bit more detail... above code is placed in the constructor of same class .. now another class when makes object of this class thread should start working and when it delets the object thread must also be end. I am getting some assertion error while some where in terminating the thread. and don't know where

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            See http://flounder.com/workerthreads.htm for how to properly shutdown a thread.


            "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

            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