91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

usleep不退出一直沉睡的發現

發布時間:2020-06-28 23:01:13 來源:網絡 閱讀:6243 作者:angel_64 欄目:編程語言

前陣子寫代碼遇到多線程下usleep會卡死的情況。
看日志是線程卡死,于是gdb進去看,但是沒有發現死鎖,還是正常的停留在usleep中了,最后才發現是usleep進去后出不來了。

周末做了個實驗,發現似乎跟機器有關,另外一臺機器就一直沒有出現這種情況。
還發現了一個情況,就是雖然usleep會卡死,但是過大概50分鐘,就會從usleep中退出來。并沒有出現永遠卡死的情況。每次出現都是卡住50分鐘后恢復,但是我的程序里面也沒有50分鐘的定時器。

發現有2個線程可能會卡死,都是循環中usleep(1000)的。
嘗試把試著把usleep的返回值打印出來,發現是否卡死后退出,都沒有返回失敗。也沒有任何一個usleep返回過失敗。
并不所有的機器都會出現,很莫名其妙。以前線上也從來沒有出現過這類問題。

很奇怪,于是群發郵件給同事,有人說make clean一把,有人不相信usleep會退步出來。

“把出問題那臺機器的目標文件全部刪掉,重新make一下試試;”
-------------------------
出問題的機器沒有編譯代碼,只是把編譯后的程序放上去了。2臺機器運行的都是同樣的執行程序。操作系統也同樣。

“遇到過,但現象不一樣,是卡死之后不會出來。
問題在于/usr/include/bits/typesizes.h中定義的__FD_SETSIZE和進程中定義的不一致。”
-----------------------
看了下2個系統的__FD_SETSIZE都一樣,進程里面也沒有重新定義__FD_SETSIZE

“這上面說是與SIGALRM信號處理有關。按理說linux里每個線程 都有進程號,usleep發的信號應該是發到線程的進程號上。但如果是發到進程組,可能會有問題,因為信號不會積累。
做個測試就可以確認了,寫個信號捕捉函數,放到主進程,等抓到SIGALRM 后,如果應該是線程的,那就可能出問題。”
--------------------
于是我寫了個簡單的程序。
發現捕獲不了usleep里面的alarm的信號

 void sigAlarmhandler(int sig)
{
 printf("\n alarm \n ");
} int main()
{
 signal(SIGALRM, sigAlarmhandler);
 while(1)
 {
  usleep(1);
 }
 return 0;
}運行,沒有任何打印。估計是usleep發出的alarm信號有單獨處理。因為usleep是個庫函數,通過調用nanosleep實現。

 

“usleep和sleep混用可能有問題”
--------------------
我把所有線程的空閑都改成了usleep,還是會出現。

 

最后的解決辦法是用select來替代usleep,不過很奇怪,gdb調試的時候變的優點卡。

順便還做了個精度測試,發現在0.1毫秒到1毫秒之間select的精度比usleep好。超過1毫秒,都相差不大。

期間還有一次select出現了1毫秒卡住1秒的情況。


 

為100微秒到10000微秒的誤差百分比
(開始時間,結束時間,真實誤差,理論誤差,差值,差值百分比)

select:975367,974213:1154:100:-1054,percent=-1054%
usleep:977413,975517:1896:100:-1796,percent=-1796%
select:978439,977463:976:200:-776,percent=-388%
usleep:980478,978486:1992:200:-1792,percent=-896%
select:981500,980526:974:300:-674,percent=-224%
usleep:983532,981547:1985:300:-1685,percent=-561%
select:984558,983581:977:400:-577,percent=-144%
usleep:986592,984609:1983:400:-1583,percent=-395%
select:987611,986640:971:500:-471,percent=-94%
usleep:988632,987658:974:500:-474,percent=-94%
select:989657,988679:978:600:-378,percent=-63%
usleep:990680,989705:975:600:-375,percent=-62%
select:991705,990727:978:700:-278,percent=-39%
usleep:993743,991752:1991:700:-1291,percent=-184%
select:994768,993789:979:800:-179,percent=-22%
usleep:996806,994815:1991:800:-1191,percent=-148%
select:997832,996853:979:900:-79,percent=-8%
usleep:999934,997879:2055:900:-1155,percent=-128%
select:895,999982:-999087:1000:1000087,percent=100008%
usleep:2928,942:1986:1000:-986,percent=-98%
select:4969,2974:1995:1100:-895,percent=-81%
usleep:7006,5016:1990:1100:-890,percent=-80%
select:9045,7052:1993:1200:-793,percent=-66%
usleep:11085,9092:1993:1200:-793,percent=-66%
select:13125,11132:1993:1300:-693,percent=-53%
usleep:16253,13172:3081:1300:-1781,percent=-137%
select:18227,16301:1926:1400:-526,percent=-37%
usleep:21275,18275:3000:1400:-1600,percent=-114%
select:23315,21322:1993:1500:-493,percent=-32%
usleep:26374,23362:3012:1500:-1512,percent=-100%
select:28414,26420:1994:1600:-394,percent=-24%
usleep:31467,28461:3006:1600:-1406,percent=-87%
select:33506,31514:1992:1700:-292,percent=-17%
usleep:36564,33553:3011:1700:-1311,percent=-77%
select:38603,36616:1987:1800:-187,percent=-10%
usleep:41654,38650:3004:1800:-1204,percent=-66%
select:43694,41701:1993:1900:-93,percent=-4%
usleep:46750,43741:3009:1900:-1109,percent=-58%
select:48789,46798:1991:2000:9,percent=0%
usleep:51844,48836:3008:2000:-1008,percent=-50%
select:54902,51891:3011:2100:-911,percent=-43%
usleep:57956,54949:3007:2100:-907,percent=-43%
select:61006,58002:3004:2200:-804,percent=-36%
usleep:64066,61054:3012:2200:-812,percent=-36%
select:67139,64113:3026:2300:-726,percent=-31%
usleep:71186,67187:3999:2300:-1699,percent=-73%
select:74249,71233:3016:2400:-616,percent=-25%
usleep:78311,74298:4013:2400:-1613,percent=-67%
select:81366,78319:3047:2500:-547,percent=-21%
usleep:85437,81374:4063:2500:-1563,percent=-62%
select:88512,85445:3067:2600:-467,percent=-17%
usleep:92585,88519:4066:2600:-1466,percent=-56%
select:95629,92592:3037:2700:-337,percent=-12%
usleep:98685,95637:3048:2700:-348,percent=-12%
select:101741,98692:3049:2800:-249,percent=-8%
usleep:105803,101753:4050:2800:-1250,percent=-44%
select:108867,105811:3056:2900:-156,percent=-5%
usleep:112937,108874:4063:2900:-1163,percent=-40%
select:115989,112945:3044:3000:-44,percent=-1%
usleep:120056,115997:4059:3000:-1059,percent=-35%
select:124130,120064:4066:3100:-966,percent=-31%
usleep:128199,124137:4062:3100:-962,percent=-31%
select:132272,128206:4066:3200:-866,percent=-27%
usleep:137361,132280:5081:3200:-1881,percent=-58%
select:141429,137368:4061:3300:-761,percent=-23%
usleep:146507,141436:5071:3300:-1771,percent=-53%
select:150591,146514:4077:3400:-677,percent=-19%
usleep:154656,150598:4058:3400:-658,percent=-19%
select:158730,154663:4067:3500:-567,percent=-16%
usleep:162796,158738:4058:3500:-558,percent=-15%
select:166896,162804:4092:3600:-492,percent=-13%
usleep:171956,166904:5052:3600:-1452,percent=-40%
select:176039,171964:4075:3700:-375,percent=-10%
usleep:181117,176046:5071:3700:-1371,percent=-37%
select:185191,181124:4067:3800:-267,percent=-7%
usleep:190281,185199:5082:3800:-1282,percent=-33%
select:194356,190288:4068:3900:-168,percent=-4%
usleep:199434,194363:5071:3900:-1171,percent=-30%
select:203505,199441:4064:4000:-64,percent=-1%
usleep:208602,203512:5090:4000:-1090,percent=-27%
select:213697,208609:5088:4100:-988,percent=-24%
usleep:218775,213704:5071:4100:-971,percent=-23%
select:223871,218783:5088:4200:-888,percent=-21%
usleep:228958,223879:5079:4200:-879,percent=-20%
select:234046,228965:5081:4300:-781,percent=-18%
usleep:239140,234054:5086:4300:-786,percent=-18%
select:244221,239147:5074:4400:-674,percent=-15%
usleep:250321,244228:6093:4400:-1693,percent=-38%
select:255427,250328:5099:4500:-599,percent=-13%
usleep:261523,255435:6088:4500:-1588,percent=-35%
select:265585,261530:4055:4600:545,percent=11%
usleep:270671,265593:5078:4600:-478,percent=-10%
select:275766,270678:5088:4700:-388,percent=-8%
usleep:281862,275774:6088:4700:-1388,percent=-29%
select:286951,281870:5081:4800:-281,percent=-5%
usleep:293058,286958:6100:4800:-1300,percent=-27%
select:298154,293065:5089:4900:-189,percent=-3%
usleep:304253,298161:6092:4900:-1192,percent=-24%
select:309335,304261:5074:5000:-74,percent=-1%
usleep:315429,309342:6087:5000:-1087,percent=-21%
select:321532,315437:6095:5100:-995,percent=-19%
usleep:327621,321540:6081:5100:-981,percent=-19%
select:333732,327628:6104:5200:-904,percent=-17%
usleep:339830,333739:6091:5200:-891,percent=-17%
select:345931,339837:6094:5300:-794,percent=-14%
usleep:352034,345939:6095:5300:-795,percent=-15%
select:358137,352042:6095:5400:-695,percent=-12%
usleep:365254,358146:7108:5400:-1708,percent=-31%
select:371365,365261:6104:5500:-604,percent=-10%
usleep:378475,371373:7102:5500:-1602,percent=-29%
select:383576,378482:5094:5600:506,percent=9%
usleep:389674,383584:6090:5600:-490,percent=-8%
select:395777,389682:6095:5700:-395,percent=-6%
usleep:402893,395785:7108:5700:-1408,percent=-24%
select:408999,402900:6099:5800:-299,percent=-5%
usleep:416116,409006:7110:5800:-1310,percent=-22%
select:422214,416124:6090:5900:-190,percent=-3%
usleep:429329,422222:7107:5900:-1207,percent=-20%
select:435457,429338:6119:6000:-119,percent=-1%
usleep:443563,435465:8098:6000:-2098,percent=-34%
select:450696,443570:7126:6100:-1026,percent=-16%
usleep:457798,450704:7094:6100:-994,percent=-16%
select:464944,457806:7138:6200:-938,percent=-15%
usleep:472052,464952:7100:6200:-900,percent=-14%
select:479164,472060:7104:6300:-804,percent=-12%
usleep:487296,479172:8124:6300:-1824,percent=-28%
select:494424,487304:7120:6400:-720,percent=-11%
usleep:502557,494432:8125:6400:-1725,percent=-26%
select:509678,502565:7113:6500:-613,percent=-9%
usleep:516792,509685:7107:6500:-607,percent=-9%
select:523917,516799:7118:6600:-518,percent=-7%
usleep:532050,523925:8125:6600:-1525,percent=-23%
select:539177,532057:7120:6700:-420,percent=-6%
usleep:547311,539186:8125:6700:-1425,percent=-21%
select:554421,547319:7102:6800:-302,percent=-4%
usleep:562539,554428:8111:6800:-1311,percent=-19%
select:569668,562550:7118:6900:-218,percent=-3%
usleep:577890,569675:8215:6900:-1315,percent=-19%
select:585017,577897:7120:7000:-120,percent=-1%
usleep:593148,585024:8124:7000:-1124,percent=-16%
select:601286,593155:8131:7100:-1031,percent=-14%
usleep:610427,601294:9133:7100:-2033,percent=-28%
select:617592,610434:7158:7200:42,percent=0%
usleep:625685,617599:8086:7200:-886,percent=-12%
select:633827,625692:8135:7300:-835,percent=-11%
usleep:641960,633835:8125:7300:-825,percent=-11%
select:650103,641968:8135:7400:-735,percent=-9%
usleep:659254,650111:9143:7400:-1743,percent=-23%
select:667420,659261:8159:7500:-659,percent=-8%
usleep:676540,667428:9112:7500:-1612,percent=-21%
select:684680,676548:8132:7600:-532,percent=-7%
usleep:692809,684688:8121:7600:-521,percent=-6%
select:700957,692817:8140:7700:-440,percent=-5%
usleep:710098,700965:9133:7700:-1433,percent=-18%
select:718237,710106:8131:7800:-331,percent=-4%
usleep:727389,718244:9145:7800:-1345,percent=-17%
select:735547,727397:8150:7900:-250,percent=-3%
usleep:744653,735555:9098:7900:-1198,percent=-15%
select:752804,744661:8143:8000:-143,percent=-1%
usleep:761970,752812:9158:8000:-1158,percent=-14%
select:771129,761979:9150:8100:-1050,percent=-12%
usleep:780270,771137:9133:8100:-1033,percent=-12%
select:789430,780278:9152:8200:-952,percent=-11%
usleep:798564,789438:9126:8200:-926,percent=-11%
select:807723,798572:9151:8300:-851,percent=-10%
usleep:816867,807731:9136:8300:-836,percent=-10%
select:826032,816874:9158:8400:-758,percent=-9%
usleep:836191,826039:10152:8400:-1752,percent=-20%
select:845370,836199:9171:8500:-671,percent=-7%
usleep:855507,845378:10129:8500:-1629,percent=-19%
select:863634,855515:8119:8600:481,percent=5%
usleep:872779,863641:9138:8600:-538,percent=-6%
select:881929,872787:9142:8700:-442,percent=-5%
usleep:892091,881937:10154:8700:-1454,percent=-16%
select:901251,892099:9152:8800:-352,percent=-4%
usleep:911417,901259:10158:8800:-1358,percent=-15%
select:919554,911424:8130:8900:770,percent=8%
usleep:929710,919567:10143:8900:-1243,percent=-13%
select:938868,929717:9151:9000:-151,percent=-1%
usleep:949031,938876:10155:9000:-1155,percent=-12%
select:959200,949039:10161:9100:-1061,percent=-11%
usleep:970374,959207:11167:9100:-2067,percent=-22%
select:979568,970382:9186:9200:14,percent=0%
usleep:989699,979575:10124:9200:-924,percent=-10%
select:999877,989707:10170:9300:-870,percent=-9%
usleep:10042,999885:-989843:9300:999143,percent=10743%
select:20206,10049:10157:9400:-757,percent=-8%
usleep:31391,20214:11177:9400:-1777,percent=-18%
select:40555,31399:9156:9500:344,percent=3%
usleep:50716,40562:10154:9500:-654,percent=-6%
select:60890,50724:10166:9600:-566,percent=-5%
usleep:72061,60897:11164:9600:-1564,percent=-16%
select:82227,72068:10159:9700:-459,percent=-4%
usleep:93418,82235:11183:9700:-1483,percent=-15%
select:102569,93425:9144:9800:656,percent=6%
usleep:113743,102582:11161:9800:-1361,percent=-13%
select:123925,113751:10174:9900:-274,percent=-2%
usleep:135098,123933:11165:9900:-1265,percent=-12%


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

中牟县| 陆川县| 米泉市| 无棣县| 九江县| 虹口区| 二手房| 临潭县| 湖南省| 鄂尔多斯市| 岚皋县| 郴州市| 巩留县| 南木林县| 都昌县| 奇台县| 邵武市| 凤庆县| 扬中市| 阳西县| 镇安县| 博乐市| 海淀区| 牡丹江市| 三台县| 恩平市| 临高县| 临潭县| 印江| 资讯| 紫阳县| 兰州市| 花垣县| 彩票| 湖口县| 巴彦县| 岫岩| 榕江县| 阳春市| 沽源县| 镇雄县|