[En-Nut-Discussion] Race condition and stack overflow in tcpsm.c

Harald Kipp harald.kipp at egnite.de
Wed Nov 19 17:02:33 CET 2014


On 19.11.2014 16:49, Harald Kipp wrote:
> On 19.11.2014 16:25, Philipp Burch wrote:
>> On 19.11.2014 14:54, Harald Kipp wrote:
>>> While Nut/OS is cooperative, mutual exclusion can be done with much less
>>> effort: 
>> I'm aware of the cooperative nature of Nut/OS and the benefits of that,
>> but I think that this solution won't be ideal here. The problem only
>> arises if two threads try to initialize the TCP state machine "at the
>> same time". When the first thread enters the function, it will set the
>> flag to 1 indicating that the initialization is complete, which is
>> actually a lie. 
> 
> Oops! Yes, you are perfectly right. My solution won't work.

Or does it? :-)

If I got it right, the problem was, that the state machine may be
started twice. As far as I can see, it doesn't generally harm, if the
state machine isn't running when NutTcpInitStateMachine() returns.

Except that NutTcpStateMachine() responds with TCP_REJECT to an early
incoming request. But that could be avoided by using the lock variable
from my example instead of the tcpThread pointer to check, whether the
NutTcpSm thread is about to start.

Regards,

Harald





More information about the En-Nut-Discussion mailing list