From: bernd on
Hi,

how is it possible to get the thread-ID for another thread which is
already running?

The postmessage is generated in thread A -> but the message should be
transmitted to thread B; the problem is, that I don`t have a handle to
thread B.

PostThreadMessage(GetThreadId(), UWM_SEND_DATA, (WPARAM)msg, 0);

Thread-A: proceed incoming data by ethernet
Thread-B: write some code to the com-port1
Thread-C: write some code to the com-port2
and son on (8 com ports) - the code is nearly the one provided by
Joseph M. Newcomer
(http://www.flounder.com/serial.htm#SerialParameters)

I`ve 8 com ports installed (each is using a different thread to write
to the com port); depending on the ethernet-data I have to call com-
port1 or com-port2 and so on.

How is it possible for me to know which thread which com port is
using? Or is it much better to use one thread for all 8 com ports
(transmitting the data)? Of course I will also need the ability to
receive information from the com ports (using worker-threads - for
each com port one thread, because I don`t know when data will be
arrived to one of these ports)

best regards
Bernd


From: Seetharam on
See if this article helps you:

Traversing the Thread List

http://msdn.microsoft.com/en-us/library/ms686852(v=VS.85).aspx

-Seetharam
From: Scott McPhillips [MVP] on
You don't need and don't want thread-ID.

When you create the threads save the pointer that is returned by
AfxBeginThread. To post a message to the thread you can then use:

pointertothread->PostThreadMessage(....);

>>> How is it possible for me to know which thread which com port is
using?

When you create a thread initialize it to TELL it which com port to use.
You're in charge.

>>> Or is it much better to use one thread for all 8 com ports
(transmitting the data)?

A transmit thread and a receive thread for each com port is a good plan.

--
Scott McPhillips [VC++ MVP]

From: Joseph M. Newcomer on
See below...
On Fri, 28 May 2010 08:11:34 -0700 (PDT), bernd <bernd.schuster12(a)googlemail.com> wrote:

>Hi,
>
>how is it possible to get the thread-ID for another thread which is
>already running?
>
>The postmessage is generated in thread A -> but the message should be
>transmitted to thread B; the problem is, that I don`t have a handle to
>thread B.
>
>PostThreadMessage(GetThreadId(), UWM_SEND_DATA, (WPARAM)msg, 0);
****
How are you creating the thread? This is extremely important!

Note that you should use AfxBeginThread, and therefore you would never call
::PostThreadMessage; You should call CWinThread::PostThreadMessage, which would know how
to find the thread ID which is stored as part of the CWinThread-derived object.
joe
****
>
>Thread-A: proceed incoming data by ethernet
>Thread-B: write some code to the com-port1
>Thread-C: write some code to the com-port2
>and son on (8 com ports) - the code is nearly the one provided by
>Joseph M. Newcomer
>(http://www.flounder.com/serial.htm#SerialParameters)
>
>I`ve 8 com ports installed (each is using a different thread to write
>to the com port); depending on the ethernet-data I have to call com-
>port1 or com-port2 and so on.
>
>How is it possible for me to know which thread which com port is
>using? Or is it much better to use one thread for all 8 com ports
>(transmitting the data)? Of course I will also need the ability to
>receive information from the com ports (using worker-threads - for
>each com port one thread, because I don`t know when data will be
>arrived to one of these ports)
>
>best regards
>Bernd
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: bernd on
> A transmit thread and a receive thread for each com port is a good plan.


Is this always a good plan independent how many com ports I`ve
installed? What`s about the performance (using only one processor)?

I mean in my case there`s only one transmit thread (sending some
message coming via ethernet to the com port) at the same time
possible, because the ethernet stream is serial. But it is always
possible to get some data at different com ports at the same time.

I`m creating the ui-thread with AfxBeginThread.

Another question: how is it possible to get the com-port number if I
receive some data? I`m using the whole function from Mr. Newcomer
(http://www.flounder.com/serial.htm)? Each tx ethernet packets has an
information from which com port the data was received.

m_serialWriteThread->parms = new CSerialPort(m_hComm, AfxGetMainWnd(),
shutdown);

With HANDLE port = this->parms->hCom; I only get the handle

best regards