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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Inter-Thread Communication

Inter-Thread Communication

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

    How can I send messages from one thread to another? I want to avoid busy/wait loops. Thank you.

    CPalliniC K C 3 Replies Last reply
    0
    • D Daniel Kanev

      How can I send messages from one thread to another? I want to avoid busy/wait loops. Thank you.

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

      If a thread has a message queue (for instance GUI threads have it) then you know how to do it. As for worker threads this page [^] may help. :)

      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
      • D Daniel Kanev

        How can I send messages from one thread to another? I want to avoid busy/wait loops. Thank you.

        K Offline
        K Offline
        killabyte
        wrote on last edited by
        #3

        I would use pipes http://msdn.microsoft.com/en-us/library/aa365781(VS.85).aspx[^]

        K 1 Reply Last reply
        0
        • D Daniel Kanev

          How can I send messages from one thread to another? I want to avoid busy/wait loops. Thank you.

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

          As a remark, it's also usefull to know that you can access the variables directly (providing you have a way to access them) from within the different threads.

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

          1 Reply Last reply
          0
          • K killabyte

            I would use pipes http://msdn.microsoft.com/en-us/library/aa365781(VS.85).aspx[^]

            K Offline
            K Offline
            killabyte
            wrote on last edited by
            #5

            wow 2 votes of 1 .... i guess i fail ;P any reason why this isn't a good messaging scheme?

            I 1 Reply Last reply
            0
            • K killabyte

              wow 2 votes of 1 .... i guess i fail ;P any reason why this isn't a good messaging scheme?

              I Offline
              I Offline
              Iain Clarke Warrior Programmer
              wrote on last edited by
              #6

              I've only just seen your post, so I'm not one of the 2 1's, but pipes are a heavy duty solution that's too cumbersome most of the time. I've used them myself between processes - the idea was that one of my processes might not even be on the same PC, so they give good flexibility. But between two threads in the same the same process, I think they're over the top. Especially for worker->ui thread communications. PostMessage works a treat, and fits nicely into the MFC message loop handling. For pipes, you'd need to alter the message pump to wait for events (you have overlapped I/O I hope!) and messages. For ui->worker thread communications, pipes are more appropriate - especially if it's opened in message mode. Iain.

              Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.

              K 1 Reply Last reply
              0
              • I Iain Clarke Warrior Programmer

                I've only just seen your post, so I'm not one of the 2 1's, but pipes are a heavy duty solution that's too cumbersome most of the time. I've used them myself between processes - the idea was that one of my processes might not even be on the same PC, so they give good flexibility. But between two threads in the same the same process, I think they're over the top. Especially for worker->ui thread communications. PostMessage works a treat, and fits nicely into the MFC message loop handling. For pipes, you'd need to alter the message pump to wait for events (you have overlapped I/O I hope!) and messages. For ui->worker thread communications, pipes are more appropriate - especially if it's opened in message mode. Iain.

                Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.

                K Offline
                K Offline
                killabyte
                wrote on last edited by
                #7

                Hmm u raise a good point, PostMessage() or PostThreadMessage() probably more applicable in this case. thinking back to when i have used pipes i have been shooting off messages then a chunk of data. i will admit i like pulling out the nail gun even if i only have to put in one nail :-\

                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