[En-Nut-Discussion] Using NutTcpReceive() and NutTcpSend() in different threads

Stephen Noftall stephenn at lcsaudio.com
Wed Feb 5 20:02:42 CET 2003


> >Is there any problem in using the TCP read and write routines on the same
> >socket in different threads? Has anyone used it this way?
>
> Should be no problem. The RS232D sample is using this and also
> some of our commercial applications.
>
> Harald

Thanks Harald for this information and the suggestion on the NutEventWait().

I will be using the dual thread method, as it looks like it works well for
the RS232 demo!

One question, which I am pretty sure I know the answer to, the threads are
not pre-emptive, correct? It looks like the timer uses a callback, which
just changes the thread's state, but doesn't call the thread. So it is up to
the threads to either call yield, or some other OS function that effectively
yields. I was concerned that there could be a timer interrupt between the
for loop where "connected" is checked, and where it calls NutTcpSend(). The
other thread could have run and killed the socket, and when it returned it
could have called NutTcpSend() with a dead socket. But if it is not
preemtive, then there is no problem.

Again, thanks for the answers!

Stephen Noftall




More information about the En-Nut-Discussion mailing list