[ECOS] ecos + lwip

Simon Kallweit simon.kallweit@intefo.ch
Wed Aug 26 11:16:00 GMT 2009

Mandeep Sandhu wrote:
> Hi all,
> I'm writing my app which makes use of the lwIP stack to send/recv packets.
> I'm using lwIP that comes along with ecos-3.0 (which I think is ver 1.1.1).
> I started by looking at the "test" examples given with lwIP. I noticed
> that ALL examples
> create 2 threads. One which simply starts and calls the following
> functions and exits:
> lwip_init();
> sys_thread_new(...)
> The thread started as part of sys_thread_new does the main
> functionality of the app.
> From the source I saw that sys_thread_new() simply allocates resources necessary
> for starting the lwIP stack and then schedules the user function for execution.
> My question:
> * Does the lwIP stack run within the context of the thread started by
> sys_thread_new()?

No, lwip runs in a thread created in lwip_init(), which is called the 
'tcpip thread' (lwip naming). The name is a bit misleading, as it 
handles more than just tcpip, it's more like a central message queue 
handler which syncs the different threads of the application to the 
stack. The stack is not thread-safe by itself. The netcomm and socket 
APIs thus use a message queue to communicate to the tcpip thread.

> * If my app has to start 2 threads, both creating separate sockets and
> send/recv data over
>   it, then should only one of them be created with a call to
> sys_thread_new()? While the other
>   one is started by our regular cyg_thread_create() and friends?

Threads that use lwip APIs (netcomm and sockets) *must* be created with 
  sys_new_thread(). Otherwise lwip's timeout mechanism will not work as 


Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

More information about the Ecos-discuss mailing list