lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] threading issues with sockets


From: Åke Forslund
Subject: [lwip-users] threading issues with sockets
Date: Wed, 20 Jun 2012 11:13:52 +0000

Hi all!

 

I’m using lwip 1.4.0 and the one thing I’ve been warned about most concerning LWIP is to BE CAREFUL when using THREADS! Pretty good advice and I’ve tried my best.

 

What I’ve done so far is to limit the number of threads using lwip and in the general case I’m down to 2 threads + lwip’s own tcpip-thread.

My current threads

enc424_listen(): a thread forwarding data to lwip using tcpip_input()

uplink(): a thread talking to our server using the socket API

then there is a third thread which is causing problems

handle_network(): when a cable-event occurs this thread is activated and runs netifapi_*()-functions to shut down the dhcp and clear the ip, gw and netmask in the netif.

 

my problems occur when the link goes down when socket thread is waiting for lwip_read() to return. (waiting for lwip_accept() causes no problems). My debugging results indicate that all threads are waiting for a semaphore which indicates a major deadlock. The really weird part is that it is not the first netifapi-call that causes problem it’s the second...

 

I’m not quite sure how to handle the situation since when using blocking sockets lwip_read() doesn’t return even if the link goes down (? is this expected behavior?) so I can’t use a semaphore to ensure that socket functions can’t be accessed at the same time as the netifapi_*()-functions.

 

Any advice on how to handle link-status changes together with sockets in a safe manner would be great.

 

Best Regards

/Åke

 

Åke Forslund

Embedded software engineer

Product Development

NIBE

Tfn: +46 (0)433 273296

E-post: address@hidden

 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]