Passing message to thread
-
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.
-
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.
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
-
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.
-
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
-
One solution is a queue STL container. Pop and insert new messages as string objects. Kuphryn
-
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.
-
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.
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
-
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.
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