Thanks for your response.
I did read about those method you mentioned. I have some troubles with each method:
1/ Using TSQ as byte stream.
This is what I chose to use. I basically write to the queue the way you described with an exception about the number of byte to write. I did as followed:
CmtWriteTSQData (tsqHandle, buffer, strlen (buffer),TSQ_INFINITE_TIMEOUT, NULL);
with buffer as the buffer containing my string. Note that strlen(buffer) is not same each time. Also a thread is doing the writing to the queue and another thread is doing the reading. This leads to my next question: How do you read these strings out?
Right now I am reading one
byte at a time with:
while (1)
{
CmtReadTSQData (tsqHandle, tempbuf, 1, 10, 0);
.....
}
in a loop, with tempbuf to contain this single char, and then store it in another buffer until I read out a CR of LF which signals the end of a string.
Will I have any problem?
Could you please provide an alternative?
2/ Using TSQ to contain pointers to strings.
I haven't tried this method since I think it requires allocation of rather large static array of buffer and also requires keeping track of these pointer in a link list.
Would you elaborate how you would use TSQ this way in my case.
3/ Lastly, the way I described in (1) works only if I have the main thread to do writing, and another thread to do reading. Some how it doesn't work when I used one thread to do writing, one thread to do reading, and the main thread to handle user interface. I found out that the program spends all its time in the reading thread (inside the while loop).
Why is it different if the writ
ing thread is the main thread? Do I miss something like priority,... or anything like that?
Thank you so much.