socket + pthread 資源佔用情形解決
在使用 pthread_create 建立 thread 處理 socket 的時候要注意,縱使 socket close 了,資源還是會被 thread 佔用住,此時要採用分離式 thread,才能在 thread 結束時自動釋放資源,最簡單的方式是建立 thread 後設定為 detach。
while (1)
{
newsockfd = accept(sockfd,
(struct sockaddr *) &cli_addr, &clilen);
if (newsockfd < 0)
exit(1);
pthread_t thread1;
pthread_create(&thread1, NULL, doSocketThread, &newsockfd );
pthread_detach(thread1);
}
訂閱:
張貼留言 (Atom)
VirtualBox 空間減肥
sdelete64 -z c: VBoxManage modifymedium disk "/Users/fellow/VirtualBox VMs/Win10/Win10.vdi" --compact *.vdi 路徑可以在 VirtualBox 儲...
-
https://github.com/ljean/modbus-tk/ install pip… sudo apt-get install python-pip install... download modbus_tk-x.x.x.tar.gz tar zxvf...
-
set0 bit 位元設0 set1 bit 位元設1 tog bit 位元0/1切換 swapc bit 位元與c切換 =================== call addr 呼叫副程式 goto addr 跳躍到標籤 icall [index] 呼叫指標指到的副程式 ig...
-
rails blog -d mysql 建立一個名為 blog 的網站app,使用 mysql cd blog 進去 gen 好的網站 config/database.yml 編輯資料庫設定 rake db:create 自動建立資料庫 ruby script/generate ...
沒有留言:
張貼留言