lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] Multi-threaded socket access once again


From: Steffen Wolfer
Subject: [lwip-users] Multi-threaded socket access once again
Date: Fri, 18 Jul 2014 11:31:01 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

Dear all,

I'm trying to access a TCP socket from multiple threads. One thread is
listening for incoming data while multiple threads are submitting data.

I've learned and understood from other postings that lwIP's sockets
are not thread safe, so I protected the calls to the send routine with
a mutex.
The receiving thread, however, blocks waiting for incoming data so I
can't use the mutex for that. But without protection, the application
crashes if there is a send call from another thread while a receive
call is active.

I resolved the issue by blocking the receive thread using an
unprotected call to select(), waiting for incoming data. Then, after
the thread has unblocked, doing a protected call to recv() that
fetches the data from lwIP.

What do you think about that? It seems to work for me but is it safe?
Or might the select() call also interfere with send() in a way that
makes the application crash at some point?

Any advice is appreciated.

Thanks,
Steffen



reply via email to

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