LwIP Application Developers Manual9---LwIP and multithreading
生活随笔
收集整理的這篇文章主要介紹了
LwIP Application Developers Manual9---LwIP and multithreading
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.前言
lwIP的內核并不是線程安全的。如果我們必須在多線程環(huán)境里使用lwIP,那么我們必須使用“upper”API層的函數(netconn或sockets)。當使用raw API時,你需要自己保護你的內核。
2.并發(fā)處理
?(1)Sockets通常來說并不能在多個應用線程中使用(在udp/raw?netconn,sendto/recv可以實現)。
?(2)一些上層操作的并發(fā)調用必須被應用層直接處理,如:socket,bind,connect,setsockopt和close。
有些情況必須要lwIP來處理(比如,要知道一個’int?socket’的調用在close/socket之間是否都相同是困難的):如下所示
Task1int s1=socket() (tell s1=5)Task1,Task2use s1 with send,recv (ok, it could be possible).Task2closesocket(s1)Task3int s2=socket() (and... it could be s2=5)Task1send(s1) !!!! Problem, s1 would not the same proto/port than the first we open, !!!! but only application can know that !!!!(3)一些操作(recv,recvfrom,send,sendto…)可以變?yōu)榫€程安全。為了使能全雙工協議,我們必須將netconn/sockets的一些處理放到api_msg
(4)一些其它需要了解的信息
- 一些特別的函數(netif_xxx和dhcp_xxx)在多線程中可能導致問題。這些函數在tcpip_thread使用相同的變量
(5)一些舉例
- 如果一個應用線程刪除了一個netif,但tcpip_thread還在運行,這個會導致一個崩潰。在同一個時間內加入2個netif將會導致接口的丟失,詳情請查看https://savannah.nongnu.org/bugs/?19347
- 如果有一個應用線程停止了一個接口的dhcp,由于netif’s?dhcp字段被dhcp’s定時器使用(在tcpip_thread線程運行),你將導致一個崩潰,詳情請查看https://savannah.nongnu.org/patch/?5798
為了避免先前2個問題,你可以使用”netif?api”,該api非常接近于‘netif’和‘dhcp’API
?
?
轉載于:https://www.cnblogs.com/smartjourneys/p/8214321.html
總結
以上是生活随笔為你收集整理的LwIP Application Developers Manual9---LwIP and multithreading的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JSP 简介(转载)
- 下一篇: GLSL中 Billboard和Poin