lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Clarification of LWIP and multi threading


From: Simon Goldschmidt
Subject: Re: [lwip-users] Clarification of LWIP and multi threading
Date: Fri, 11 Feb 2011 14:38:01 +0100

David Hammerton <address@hidden> wrote:

> I need a bit of clarification on using lwip in a multi-threaded
> environment.
> The wiki page (http://lwip.wikia.com/wiki/LwIP_and_multithreading) is a
> little vague, as is this email response: (
> http://www.mail-archive.com/address@hidden/msg07800.html)

I agree abotu the wiki (in fact, the information there is somwhere between 
misleading and wrong), but what's vague about my email?

"Both the netconn and the socket API are thread-safe as long as you don't share 
one netconn/socket between multiple threads (i.e. don't access it from more 
than one thread at a time)."

What you want to do is sharing a connection between threads: one thread for 
reading, one thread for writing. That's not supported, simple as that.

> By the looks of it, netconn_send goes
> through a message (either using a lock or a message queue), so I think it
> should be safe?

That's what the wiki talks about, I guess. However, while this *might* work for 
UDP, it's not something it's supposed to do. If it works, it does so "by 
accident".

> Also, how am I supposed to use the callback provided
> to netconn_new_with_proto_and_callback? Should I/Can I be calling
> netconn_recv in the thread context of the callback? If not, how can I
> abort
> a netconn_recv if, for example, I need to shut down the connection?

The callback is used for socket select(), for example. It gets called from 
tcpip_thread, so if you implement your own callback, it has to be thread-safe.

Using a select-like mechanism is usually the way to go with lwIP (instead of 
having different threads for TX/RX).

Simon
-- 
GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit 
gratis Handy-Flat! http://portal.gmx.net/de/go/dsl



reply via email to

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