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. Passing message to thread

Passing message to thread

Scheduled Pinned Locked Moved C / C++ / MFC
c++helplearning
8 Posts 6 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 Offline
    S Offline
    Samrah Saulat Mirza
    wrote on last edited by
    #1

    Firends i am having a problem and i like your advice in this regard. I would appreciate the non-MFC answer. I've a thread. The purpose of this thread is to read string from somewhere and then display it on the console. Lets call it thread A. So simple, so easy. I've two other threads. The purpose of these threads is to get some data from internet. Now, what i want is that the two threads getting data from internet should "send" the string to thread A, so that it can be displayed. But i don't want those two threads to block. And this is the problem. Of course two threads should write string somewhere and then thread A get those strings periodically. As such critical section is necessary which i like to prevent because as such there is a blocking. In order to overcome the problem i am using IO completion ports. But the problem is that IOCP is not available in Win9X family operating systems. So what you like to advice me.

    N V C 3 Replies Last reply
    0
    • S Samrah Saulat Mirza

      Firends i am having a problem and i like your advice in this regard. I would appreciate the non-MFC answer. I've a thread. The purpose of this thread is to read string from somewhere and then display it on the console. Lets call it thread A. So simple, so easy. I've two other threads. The purpose of these threads is to get some data from internet. Now, what i want is that the two threads getting data from internet should "send" the string to thread A, so that it can be displayed. But i don't want those two threads to block. And this is the problem. Of course two threads should write string somewhere and then thread A get those strings periodically. As such critical section is necessary which i like to prevent because as such there is a blocking. In order to overcome the problem i am using IO completion ports. But the problem is that IOCP is not available in Win9X family operating systems. So what you like to advice me.

      N Offline
      N Offline
      Nitron
      wrote on last edited by
      #2

      If it's simply a reader/writer paradigm, why not use a volatile string in the calling thread and write static Get/Set member functions that can be called via a pointer to the calling thread? - Nitron


      "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

      L 1 Reply Last reply
      0
      • S Samrah Saulat Mirza

        Firends i am having a problem and i like your advice in this regard. I would appreciate the non-MFC answer. I've a thread. The purpose of this thread is to read string from somewhere and then display it on the console. Lets call it thread A. So simple, so easy. I've two other threads. The purpose of these threads is to get some data from internet. Now, what i want is that the two threads getting data from internet should "send" the string to thread A, so that it can be displayed. But i don't want those two threads to block. And this is the problem. Of course two threads should write string somewhere and then thread A get those strings periodically. As such critical section is necessary which i like to prevent because as such there is a blocking. In order to overcome the problem i am using IO completion ports. But the problem is that IOCP is not available in Win9X family operating systems. So what you like to advice me.

        V Offline
        V Offline
        valikac
        wrote on last edited by
        #3

        One solution is a queue STL container. Pop and insert new messages as string objects. Kuphryn

        L 1 Reply Last reply
        0
        • N Nitron

          If it's simply a reader/writer paradigm, why not use a volatile string in the calling thread and write static Get/Set member functions that can be called via a pointer to the calling thread? - Nitron


          "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Nitron wrote: If it's simply a reader/writer paradigm, No, its not simply like that. I need to implement some sort of message queue just like IO completion port.

          1 Reply Last reply
          0
          • V valikac

            One solution is a queue STL container. Pop and insert new messages as string objects. Kuphryn

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            kuphryn wrote: One solution is a queue STL container. But as such i need to make this queue thread safe using critical section; otherwise two different threads may want to read and write at this object the same time.

            V P 2 Replies Last reply
            0
            • L Lost User

              kuphryn wrote: One solution is a queue STL container. But as such i need to make this queue thread safe using critical section; otherwise two different threads may want to read and write at this object the same time.

              V Offline
              V Offline
              valikac
              wrote on last edited by
              #6

              Correct. Kuphryn

              1 Reply Last reply
              0
              • L Lost User

                kuphryn wrote: One solution is a queue STL container. But as such i need to make this queue thread safe using critical section; otherwise two different threads may want to read and write at this object the same time.

                P Offline
                P Offline
                Peter Weyzen
                wrote on last edited by
                #7

                You can't avoid that... Though the other cheap way, is to post messages to your own window. You can pass the strings by converting them to atom's (see GlobalAddAtom). If you don't have a window, then go back to plan A as mentioned above. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Peter Weyzen Staff Engineer Santa Cruz Networks

                1 Reply Last reply
                0
                • S Samrah Saulat Mirza

                  Firends i am having a problem and i like your advice in this regard. I would appreciate the non-MFC answer. I've a thread. The purpose of this thread is to read string from somewhere and then display it on the console. Lets call it thread A. So simple, so easy. I've two other threads. The purpose of these threads is to get some data from internet. Now, what i want is that the two threads getting data from internet should "send" the string to thread A, so that it can be displayed. But i don't want those two threads to block. And this is the problem. Of course two threads should write string somewhere and then thread A get those strings periodically. As such critical section is necessary which i like to prevent because as such there is a blocking. In order to overcome the problem i am using IO completion ports. But the problem is that IOCP is not available in Win9X family operating systems. So what you like to advice me.

                  C Offline
                  C Offline
                  cmk
                  wrote on last edited by
                  #8

                  Read the docs for PostThreadMessage(). It will explain how to create a message queue for your thread A (dead easy). Threads B, C can then call PostThreadMessage(thread_A, MY_STR_MSG, char*, length). Thread A (even though it doesn't have a window) can use the normal window GetMessage() loop to pull the strings from the message queue. Probably want to alloc memory for strings in threads B,C and delete in thread A. ...cmk

                  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