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

Thread

Scheduled Pinned Locked Moved C / C++ / MFC
help
14 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.
  • S susanne1

    Hallo, I have the following problem with the Thread: I create the Thread first as SUSPENDED, but it does not start at the expectetd time. First the Program calls this function: ThreadStart(); /////////////////////////////// ThreadStart() { if (m_pSelThread != NULL) { if (::WaitForSingleObject(m_pSelThread->m_hThread, 0) != WAIT_OBJECT_0) return; delete m_pSelThread; m_pSelThread = NULL; } ::WaitForSingleObject(m_SEl_Start_Event, 0); m_SEl_Start_Event.SetEvent (); // CEvent Object CWinThread* m_pSelThread = AfxBeginThread(ThreadFunktion, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); m_pSelThread->m_bAutoDelete = FALSE; m_pSelThread->ResumeThread(); } UINT ThreadFunktion ( LPVOID param ) { if (param == NULL) return -1; DoSomeThing(); return 0; } The Thread does not come to the UINT ThreadFunktion(LPVOID param). Any help would be appriciated.

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

    susanne1 wrote:

    CWinThread* m_pSelThread = AfxBeginThread(ThreadFunktion, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);

    Shouldn't that be:

    m_pSelThread = AfxBeginThread(ThreadFunktion, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);

    i.e. you're hiding the class member variable with the local one. :)

    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?

    S 1 Reply Last reply
    0
    • CPalliniC CPallini

      susanne1 wrote:

      CWinThread* m_pSelThread = AfxBeginThread(ThreadFunktion, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);

      Shouldn't that be:

      m_pSelThread = AfxBeginThread(ThreadFunktion, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);

      i.e. you're hiding the class member variable with the local one. :)

      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]

      S Offline
      S Offline
      susanne1
      wrote on last edited by
      #3

      Okay i did it like that defining the Thread Pointer in the header File, but this deos not help.

      1 Reply Last reply
      0
      • S susanne1

        Hallo, I have the following problem with the Thread: I create the Thread first as SUSPENDED, but it does not start at the expectetd time. First the Program calls this function: ThreadStart(); /////////////////////////////// ThreadStart() { if (m_pSelThread != NULL) { if (::WaitForSingleObject(m_pSelThread->m_hThread, 0) != WAIT_OBJECT_0) return; delete m_pSelThread; m_pSelThread = NULL; } ::WaitForSingleObject(m_SEl_Start_Event, 0); m_SEl_Start_Event.SetEvent (); // CEvent Object CWinThread* m_pSelThread = AfxBeginThread(ThreadFunktion, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); m_pSelThread->m_bAutoDelete = FALSE; m_pSelThread->ResumeThread(); } UINT ThreadFunktion ( LPVOID param ) { if (param == NULL) return -1; DoSomeThing(); return 0; } The Thread does not come to the UINT ThreadFunktion(LPVOID param). Any help would be appriciated.

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

        susanne1 wrote:

        ::WaitForSingleObject(m_SEl_Start_Event, 0);

        What is the purpose of the above call? :)

        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?

        S 1 Reply Last reply
        0
        • CPalliniC CPallini

          susanne1 wrote:

          ::WaitForSingleObject(m_SEl_Start_Event, 0);

          What is the purpose of the above call? :)

          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]

          S Offline
          S Offline
          susanne1
          wrote on last edited by
          #5

          to wait for the event to happen.

          CPalliniC 1 Reply Last reply
          0
          • S susanne1

            Hallo, I have the following problem with the Thread: I create the Thread first as SUSPENDED, but it does not start at the expectetd time. First the Program calls this function: ThreadStart(); /////////////////////////////// ThreadStart() { if (m_pSelThread != NULL) { if (::WaitForSingleObject(m_pSelThread->m_hThread, 0) != WAIT_OBJECT_0) return; delete m_pSelThread; m_pSelThread = NULL; } ::WaitForSingleObject(m_SEl_Start_Event, 0); m_SEl_Start_Event.SetEvent (); // CEvent Object CWinThread* m_pSelThread = AfxBeginThread(ThreadFunktion, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); m_pSelThread->m_bAutoDelete = FALSE; m_pSelThread->ResumeThread(); } UINT ThreadFunktion ( LPVOID param ) { if (param == NULL) return -1; DoSomeThing(); return 0; } The Thread does not come to the UINT ThreadFunktion(LPVOID param). Any help would be appriciated.

            R Offline
            R Offline
            Rajesh R Subramanian
            wrote on last edited by
            #6

            Can't you just start the thread and wait for the event to happen within the thread before executing code? What's all this mess about? Why are you setting the m_bAutoDelete member to false? I see you may delete it manually, but *what* is the purpose of it?

            It is a crappy thing, but it's life -^ Carlo Pallini

            S CPalliniC 2 Replies Last reply
            0
            • R Rajesh R Subramanian

              Can't you just start the thread and wait for the event to happen within the thread before executing code? What's all this mess about? Why are you setting the m_bAutoDelete member to false? I see you may delete it manually, but *what* is the purpose of it?

              It is a crappy thing, but it's life -^ Carlo Pallini

              S Offline
              S Offline
              susanne1
              wrote on last edited by
              #7

              the thread mus t be created but not start immediately, autodelte false to tell him not to delet himself.

              R 1 Reply Last reply
              0
              • S susanne1

                to wait for the event to happen.

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

                That doesn't make sense. Anyway I made a test on my system: Without hiding the class member variable, the thread starts happily. :)

                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
                • S susanne1

                  the thread mus t be created but not start immediately, autodelte false to tell him not to delet himself.

                  R Offline
                  R Offline
                  Rajesh R Subramanian
                  wrote on last edited by
                  #9

                  So, why should it not start immediately? Can't you just start it immediately, but not execute any code until the interested event happens? I asked for the reason behind your approach. I did not ask you what m_bAutoDelete is for. Tell me why do *you* want the thread not to delete itself.

                  It is a crappy thing, but it's life -^ Carlo Pallini

                  1 Reply Last reply
                  0
                  • R Rajesh R Subramanian

                    Can't you just start the thread and wait for the event to happen within the thread before executing code? What's all this mess about? Why are you setting the m_bAutoDelete member to false? I see you may delete it manually, but *what* is the purpose of it?

                    It is a crappy thing, but it's life -^ Carlo Pallini

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

                    Rajesh R Subramanian wrote:

                    Why are you setting the m_bAutoDelete member to false? I see you may delete it manually, but *what* is the purpose of it?

                    Well you may want to do that, I mean that's nothing wrong in doing it (and that's the reason for delaying the thread start). :)

                    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?

                    R 1 Reply Last reply
                    0
                    • CPalliniC CPallini

                      Rajesh R Subramanian wrote:

                      Why are you setting the m_bAutoDelete member to false? I see you may delete it manually, but *what* is the purpose of it?

                      Well you may want to do that, I mean that's nothing wrong in doing it (and that's the reason for delaying the thread start). :)

                      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]

                      R Offline
                      R Offline
                      Rajesh R Subramanian
                      wrote on last edited by
                      #11

                      No, I asked why did he want to delete it manually (as opposed to leave it die in its way). There could be valid reasons, I wanted to know the OP's reason. :)

                      It is a crappy thing, but it's life -^ Carlo Pallini

                      CPalliniC 1 Reply Last reply
                      0
                      • R Rajesh R Subramanian

                        No, I asked why did he want to delete it manually (as opposed to leave it die in its way). There could be valid reasons, I wanted to know the OP's reason. :)

                        It is a crappy thing, but it's life -^ Carlo Pallini

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

                        You're right: there could be valid reasons, anyway you're very (and, of course, politely) curious about her reason. :rolleyes:

                        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?

                        R 1 Reply Last reply
                        0
                        • CPalliniC CPallini

                          You're right: there could be valid reasons, anyway you're very (and, of course, politely) curious about her reason. :rolleyes:

                          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]

                          R Offline
                          R Offline
                          Rajesh R Subramanian
                          wrote on last edited by
                          #13

                          Of course, politeness is guaranteed (or 100% money back), after Mr. Maunder's new commandment. :)

                          It is a crappy thing, but it's life -^ Carlo Pallini

                          CPalliniC 1 Reply Last reply
                          0
                          • R Rajesh R Subramanian

                            Of course, politeness is guaranteed (or 100% money back), after Mr. Maunder's new commandment. :)

                            It is a crappy thing, but it's life -^ Carlo Pallini

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

                            :-D BTW there's a polite way to advice someone to stop using threads? :rolleyes:

                            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]

                            modified on Wednesday, August 12, 2009 10:59 AM

                            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