{"id":1156,"date":"2016-04-04T21:25:36","date_gmt":"2016-04-04T13:25:36","guid":{"rendered":"http:\/\/ufqi.com\/blog\/?p=1156"},"modified":"2016-04-04T22:01:46","modified_gmt":"2016-04-04T14:01:46","slug":"multiple-thread-locks","status":"publish","type":"post","link":"https:\/\/ufqi.com\/blog\/multiple-thread-locks\/","title":{"rendered":"\u591a\u7ebf\u7a0b\u540c\u6b65\u7684\u9501\uff1a\u4e92\u65a5\u9501\u548c\u8bfb\u5199\u9501"},"content":{"rendered":"<p>\u5728 -maimai \u4e0a\u8bfb\u5230\u53bb\u963f\u91cc\u7684\u540c\u5b66\u8003\u5bdf\u591a\u7ebf\u7a0b\u7684\u9501\u95ee\u9898\uff0c\u60f3\u8d77\u65e9\u51e0\u5e74\u5199\u7684\u4e00\u4e2a\u7528Java\u5b9e\u73b0\u7684Session Server\uff08\u73b0\u5728\u8fd8\u5728\u670d\u5f79\u4e2d\uff09\uff0c\u8d77\u521d\u662f\u57fa\u4e8eJava\u7684Synchronized\u7528\u5728\u65b9\u6cd5\u548c\u5bf9\u8c61\u4e0a\uff0c\u540e\u6765\u6539\u7531ConcurrentHashMap\u505a\u5bb9\u5668\u3002\u53c2\u7167 -ChinaUnix \u4e0a\uff0cifndef \u7ed9\u4f8b\u5b50\uff08<b><a href=\"http:\/\/labs.people.com.cn\/url4p\/index.php?sid=315512&amp;act=query&amp;shortkey=92TQ\" target=\"_blank\">-R\/92TQ<\/a>\u00a0<\/b>\uff09\uff0c\u6211\u91cd\u590d\u4e86\u4e00\u4e0b\u8fd9\u4e2a\u5b9e\u9a8c\uff0c\u7b97\u662f\u5bf9\u4e92\u65a5\u9501\u548c\u8bfb\u5199\u9501\u7684\u4e00\u79cd\u56de\u987e\u3002<\/p>\n<blockquote><p>\u6982\u5ff5\uff0c\u201c\u7ebf\u7a0b\u540c\u6b65\u7b80\u5355\u7684\u8bf4\u5c31\u662f\u5f53\u591a\u4e2a\u7ebf\u7a0b\u5171\u4eab\u76f8\u540c\u7684\u5185\u5b58\u65f6\uff0c\u5f53\u67d0\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u4fee\u6539\u53d8\u91cf\uff0c\u800c\u5176\u4ed6\u7ebf\u7a0b\u4e5f\u53ef\u4ee5\u8bfb\u53d6\u6216\u4fee\u6539\u8fd9\u4e2a\u53d8\u91cf\u7684\u65f6\u5019\uff0c\u5c31\u9700\u8981\u5bf9\u8fd9\u4e9b\u7ebf\u7a0b\u8fdb\u884c\u540c\u6b65\uff0c\u4ee5\u786e\u4fdd\u4ed6\u4eec\u5728\u8bbf\u95ee\u53d8\u91cf\u7684\u5b58\u50a8\u5185\u5bb9\u65f6\u4e0d\u4f1a\u8bbf\u95ee\u5230\u65e0\u6548\u7684\u6570\u503c\u3002\u201d\uff0c\u786e\u4fdd\u540c\u6b65\u7684\u63aa\u65bd\u662f\u5728\u64cd\u4f5c\u524d\u8fdb\u884c\u52a0\u9501\u3002<\/p>\n<p>\u4e92\u65a5\u9501, \u201c\u6211\u4eec\u53ef\u4ee5\u628a\u4e92\u65a5\u91cf\u60f3\u6210\u4e00\u628a\u9501\u3002\u5728\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\u524d \u5bf9\u4e92\u65a5\u91cf\u8fdb\u884c\u52a0\u9501\uff0c\u5728\u8bbf\u95ee\u5b8c\u540e\u91ca\u653e\u4e92\u65a5\u91cf\u4e0a\u7684\u9501\u3002<br \/>\n\u5bf9\u4e92\u65a5\u91cf\u8fdb\u884c\u52a0\u9501\u540e\uff0c\u4efb\u4f55\u5176\u4ed6\u8bd5\u56fe\u518d\u5bf9\u8be5\u4e92\u65a5\u91cf\u52a0\u9501\u7684\u7ebf\u7a0b\u90fd\u4f1a\u88ab\u963b\u585e\u76f4\u5230\u5f53\u524d\u6301\u6709\u9501\u7684\u7ebf\u7a0b\u91ca\u653e\u9501\u3002\u201d<\/p>\n<p>\u8bfb\u5199\u9501, \u201c\u5f53\u8bfb\u5199\u9501\u662f\u5199\u52a0\u9501\u65f6\uff0c\u5728\u8fd9\u4e2a\u9501\u88ab\u89e3\u9501\u4e4b\u524d\uff0c\u6240\u6709\u8bd5\u56fe\u5bf9\u8fd9\u4e2a\u9501\u52a0\u9501\u7684\u7ebf\u7a0b\u90fd\u4f1a\u88ab\u963b\u585e\u3002<br \/>\n\u5f53\u8bfb\u5199\u9501\u662f\u8bfb\u52a0\u9501\u65f6\uff0c\u5728\u8fd9\u4e2a\u9501\u88ab\u89e3\u9501\u4e4b\u524d\uff0c\u6240\u6709\u8bd5\u56fe\u4ee5\u8bfb\u6a21\u5f0f\u5bf9\u4ed6\u8fdb\u884c\u52a0\u9501\u7684\u7ebf\u7a0b\u90fd\u53ef\u4ee5\u5f97\u5230\u8bbf\u95ee\u6743\u201d\u3002<\/p><\/blockquote>\n<p>\u6839\u636e\u5982\u4e0a\u63cf\u8ff0\uff0c\u4ee5\u53caJava SDK\u4e2d\u5bf9 Synchronized\u548cConcurrentHashMap\u7684\u63cf\u8ff0\uff0c<\/p>\n<blockquote><p>Synchronized\uff0c\u201c\u00a0it is not possible for two invocations of synchronized methods on the same object to interleave. When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object.\u201d(<b><a href=\"http:\/\/labs.people.com.cn\/url4p\/index.php?sid=315512&amp;act=query&amp;shortkey=P2Tc\" target=\"_blank\">-R\/P2Tc<\/a>\u00a0<\/b>)<\/p>\n<p>ConcurrentHashMap\uff0c\u201d\u00a0even though all operations are thread-safe, retrieval operations do\u00a0not\u00a0entail locking, and there is\u00a0not\u00a0any support for locking the entire table in a way that prevents all access.\u00a0\u201d(<b><a href=\"http:\/\/labs.people.com.cn\/url4p\/index.php?sid=315512&amp;act=query&amp;shortkey=22Uk\" target=\"_blank\">-R\/22Uk<\/a>\u00a0<\/b>) \u2026\u201cIt\u00a0uses a multitude of locks, each lock controls one segment of the hash. When setting data in a particular segment, the lock for that segment is obtained.\u201d(<b><a href=\"http:\/\/labs.people.com.cn\/url4p\/index.php?sid=315512&amp;act=query&amp;shortkey=b2Tc\" target=\"_blank\">-R\/b2Tc<\/a>\u00a0<\/b>)<\/p><\/blockquote>\n<p>\u4ece\u4e0a\u6587\u7684\u63cf\u8ff0\u6765\u770b\uff0cSynchronized\u7684\u5b9e\u73b0\u7c7b\u4f3c\u4e92\u65a5\u9501\uff0c\u800cConcurrentHashMap\u7684\u5b9e\u73b0\u7c7b\u4f3c\u4e8e\u8bfb\u5199\u9501\u3002<\/p>\n<p>\u5b9e\u9645\u7684\u4f8b\u5b50\uff0c\u82e5\u591a\u7ebf\u7a0b\u4e0d\u52a0\u9501\uff0c\u8fd0\u884c\u7684\u7ed3\u679c\u5c06\u5f88\u5f02\u5e38\uff0c\u5982\u4e0b\u7a0b\u5e8f:<\/p>\n<div>\/*<\/div>\n<div>\u00a0* pthread mutex lock, rwlock test<br \/>\n* wadelau@ufqi.com, Mon Apr \u00a04 21:32:27 CST 2016<\/div>\n<div>\u00a0*\/<\/div>\n<div>#include &lt;stdio.h&gt;<\/div>\n<div>#include &lt;stdlib.h&gt;<\/div>\n<div>#include &lt;string.h&gt;<\/div>\n<div>#include &lt;pthread.h&gt;<\/div>\n<div>#include &lt;unistd.h&gt;<\/div>\n<div>#include &lt;errno.h&gt;<\/div>\n<div>#include &lt;ctype.h&gt;<\/div>\n<div><\/div>\n<div>int i = 0;<\/div>\n<div>static int COUNT_NUM = 1000000;<\/div>\n<div><\/div>\n<div>static void *thread_1();<\/div>\n<div>static void *thread_2();<\/div>\n<div><\/div>\n<div><\/div>\n<div>int main(void){<\/div>\n<div><\/div>\n<div>int err;<\/div>\n<div>pthread_t th1, th2;<\/div>\n<div>err = pthread_create(&amp;th1, NULL, thread_1, (void *)0);<\/div>\n<div>if(err != 0){<\/div>\n<div>printf(\u201cCreate new thread error: %s\\n\u201d, strerror(err));<\/div>\n<div>exit(0);<\/div>\n<div>}<\/div>\n<div>err = pthread_create(&amp;th2, NULL, thread_2, (void *)0);<\/div>\n<div>if(err != 0){<\/div>\n<div>printf(\u201cCreate new thread error: %s\\n\u201d, strerror(err));<\/div>\n<div>exit(0);<\/div>\n<div>}<\/div>\n<div><\/div>\n<div>err = pthread_join(th1, NULL);<\/div>\n<div>if( err != 0){<\/div>\n<div>printf(\u201cWait thread done error: %s\\n\u201d, strerror(err));<\/div>\n<div>exit(0);<\/div>\n<div>}<\/div>\n<div><\/div>\n<div>err = pthread_join(th2, NULL);<\/div>\n<div>if( err != 0){<\/div>\n<div>printf(\u201cWait thread done error: %s\\n\u201d, strerror(err));<\/div>\n<div>exit(0);<\/div>\n<div>}<\/div>\n<div><\/div>\n<div>printf(\u201ci=%d\\n\u201d, i);<\/div>\n<div><\/div>\n<div>exit(0);<\/div>\n<div><\/div>\n<div>}<\/div>\n<div><\/div>\n<div><\/div>\n<div>static void *thread_1(void *args){<\/div>\n<div><\/div>\n<div>int j;<\/div>\n<div>for(j=0; j&lt;COUNT_NUM; j++){<\/div>\n<div>i++;<\/div>\n<div>}<\/div>\n<div>pthread_exit((void *)0);<\/div>\n<div><\/div>\n<div>}<\/div>\n<div><\/div>\n<div><\/div>\n<div>static void *thread_2(void *args){<\/div>\n<div><\/div>\n<div>int j;<\/div>\n<div>for(j=0; j&lt;COUNT_NUM; j++){<\/div>\n<div>i++;<\/div>\n<div>}<\/div>\n<div>pthread_exit((void *)0);<\/div>\n<div><\/div>\n<div>}<\/div>\n<div><\/div>\n<p>\u7f16\u8bd1\u65f6\uff0c\u4f7f\u7528\uff1a<\/p>\n<p>shell&gt;\u00a0gcc -lpthread xxx.c \u00a0-o xxx.out<\/p>\n<p>\u7a0b\u5e8f\u8fd0\u884c\u5341\u6b21\u7684\u7ed3\u679c\u5404\u4e0d\u76f8\u540c\uff1a<\/p>\n<p>shell&gt; for i in {0..9}; do .\/pthread_nolock.out; done;<\/p>\n<div>i=1042904<\/div>\n<div>i=1064909<\/div>\n<div>i=1026858<\/div>\n<div>i=1038045<\/div>\n<div>i=1133655<\/div>\n<div>i=1085719<\/div>\n<div>i=1029224<\/div>\n<div>i=1089466<\/div>\n<div>i=1020473<\/div>\n<div>i=1041702<\/div>\n<div><\/div>\n<p>\u5bf9\u7ebf\u7a0b\u4f7f\u7528\u4e92\u65a5\u9501:<\/p>\n<div>static int COUNT_NUM = 1000000;<br \/>\npthread_mutex_t mutex;<\/div>\n<div><\/div>\n<div><\/div>\n<div>\n<div>pthread_mutex_init(&amp;mutex, NULL);<\/div>\n<div>err = pthread_create(&amp;th1, NULL, thread_1, (void *)0);<\/div>\n<div><\/div>\n<\/div>\n<div><\/div>\n<div>\n<div>pthread_mutex_destroy(&amp;mutex);<\/div>\n<div>printf(\u201ci=%d\\n\u201d, i);<\/div>\n<div><\/div>\n<\/div>\n<div><\/div>\n<div>\n<div>for(j=0; j&lt;COUNT_NUM; j++){<\/div>\n<div>pthread_mutex_lock(&amp;mutex);<\/div>\n<div>i++;<\/div>\n<div>pthread_mutex_unlock(&amp;mutex);<\/div>\n<div>}<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>\u518d\u6b21\u8fd0\u884c\u7684\u7ed3\u679c\uff1a<\/p>\n<div>shell&gt; for i in {0..9}; do .\/pthread_mutex.out ; done;<\/div>\n<div>i=2000000<\/div>\n<div>i=2000000<\/div>\n<div>i=2000000<\/div>\n<div>i=2000000<\/div>\n<div>i=2000000<\/div>\n<div>i=2000000<\/div>\n<div>i=2000000<\/div>\n<div>i=2000000<\/div>\n<div>i=2000000<\/div>\n<div>i=2000000<\/div>\n<div><\/div>\n<p>\u5df2\u7ecf\u5b8c\u5168\u7b26\u5408\u9884\u671f\u4e86\u3002 \u518d\u5bf9\u7ebf\u7a0b\u4f7f\u7528\u8bfb\u5199\u9501\u3002\u4ee3\u7801\u53d8\u5316\uff1a<\/p>\n<div>static int COUNT_NUM = 1000000;<\/div>\n<div>\/\/pthread_mutex_t mutex;<\/div>\n<div>pthread_rwlock_t rwlock;<\/div>\n<div><\/div>\n<div><\/div>\n<div>\n<div>\/\/pthread_mutex_init(&amp;mutex, NULL);<\/div>\n<div>pthread_rwlock_init(&amp;rwlock, NULL);<\/div>\n<div>err = pthread_create(&amp;th1, NULL, thread_1, (void *)0);<\/div>\n<\/div>\n<div><\/div>\n<div><\/div>\n<div>\n<div>\/\/pthread_mutex_destroy(&amp;mutex);<\/div>\n<div>pthread_rwlock_destroy(&amp;rwlock);<\/div>\n<div>printf(\u201ci=%d\\n\u201d, i);<\/div>\n<\/div>\n<div><\/div>\n<div><\/div>\n<div>\n<div>\u00a0volatile int a;<\/div>\n<div>\u00a0for(j=0; j&lt;COUNT_NUM; j++){<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 pthread_rwlock_rdlock(&amp;rwlock);<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 a = i;<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 pthread_rwlock_rdlock(&amp;rwlock);<\/div>\n<div>\u00a0}<\/div>\n<div><\/div>\n<div><\/div>\n<\/div>\n<p>\u518d\u6b21\u8fd0\u884c\u7a0b\u5e8f\uff0c\u5e76\u8ba1\u65f6\uff0c\u770b\u770b\u8bfb\u5199\u9501\u7684\u7a0b\u5e8f\u65f6\u95f4\uff1a<\/p>\n<div>shell&gt; for i in {0..9}; do time .\/pthread_rwlock_rd.out ; done;<\/div>\n<div>i=1000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.534s<\/div>\n<div>user \u00a0 \u00a00m0.576s<\/div>\n<div>sys \u00a0 \u00a0 0m0.460s<\/div>\n<div>i=1000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.333s<\/div>\n<div>user \u00a0 \u00a00m0.392s<\/div>\n<div>sys \u00a0 \u00a0 0m0.232s<\/div>\n<div>i=1000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.282s<\/div>\n<div>user \u00a0 \u00a00m0.340s<\/div>\n<div>sys \u00a0 \u00a0 0m0.180s<\/div>\n<div>i=1000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.336s<\/div>\n<div>user \u00a0 \u00a00m0.340s<\/div>\n<div>sys \u00a0 \u00a0 0m0.288s<\/div>\n<div>i=1000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.278s<\/div>\n<div>user \u00a0 \u00a00m0.324s<\/div>\n<div>sys \u00a0 \u00a0 0m0.188s<\/div>\n<div>i=1000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.224s<\/div>\n<div>user \u00a0 \u00a00m0.268s<\/div>\n<div>sys \u00a0 \u00a0 0m0.124s<\/div>\n<div>i=1000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.257s<\/div>\n<div>user \u00a0 \u00a00m0.272s<\/div>\n<div>sys \u00a0 \u00a0 0m0.192s<\/div>\n<div>i=1000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.261s<\/div>\n<div>user \u00a0 \u00a00m0.296s<\/div>\n<div>sys \u00a0 \u00a0 0m0.176s<\/div>\n<div>i=1000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.258s<\/div>\n<div>user \u00a0 \u00a00m0.256s<\/div>\n<div>sys \u00a0 \u00a0 0m0.212s<\/div>\n<div>i=1000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.366s<\/div>\n<div>user \u00a0 \u00a00m0.420s<\/div>\n<div>sys \u00a0 \u00a0 0m0.272s<\/div>\n<p>&nbsp;<\/p>\n<p>\u540c\u65f6\u8fd0\u884c\u4f7f\u7528\u4e92\u65a5\u9501\u7a0b\u5e8f\u5e76\u8ba1\u65f6\uff0c\u6570\u636e\u5982\u4e0b\uff1a<\/p>\n<div>shell&gt; for i in {0..9}; do time .\/pthread_mutex_rd.out ; done;<\/div>\n<div>i=2000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.178s<\/div>\n<div>user \u00a0 \u00a00m0.168s<\/div>\n<div>sys \u00a0 \u00a0 0m0.140s<\/div>\n<div>i=2000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.183s<\/div>\n<div>user \u00a0 \u00a00m0.176s<\/div>\n<div>sys \u00a0 \u00a0 0m0.140s<\/div>\n<div>i=2000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.177s<\/div>\n<div>user \u00a0 \u00a00m0.188s<\/div>\n<div>sys \u00a0 \u00a0 0m0.120s<\/div>\n<div>i=2000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.183s<\/div>\n<div>user \u00a0 \u00a00m0.168s<\/div>\n<div>sys \u00a0 \u00a0 0m0.152s<\/div>\n<div>i=2000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.198s<\/div>\n<div>user \u00a0 \u00a00m0.152s<\/div>\n<div>sys \u00a0 \u00a0 0m0.196s<\/div>\n<div>i=2000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.168s<\/div>\n<div>user \u00a0 \u00a00m0.124s<\/div>\n<div>sys \u00a0 \u00a0 0m0.160s<\/div>\n<div>i=2000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.155s<\/div>\n<div>user \u00a0 \u00a00m0.160s<\/div>\n<div>sys \u00a0 \u00a0 0m0.100s<\/div>\n<div>i=2000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.165s<\/div>\n<div>user \u00a0 \u00a00m0.148s<\/div>\n<div>sys \u00a0 \u00a0 0m0.136s<\/div>\n<div>i=2000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.160s<\/div>\n<div>user \u00a0 \u00a00m0.140s<\/div>\n<div>sys \u00a0 \u00a0 0m0.132s<\/div>\n<div>i=2000000<\/div>\n<div><\/div>\n<div>real \u00a0 \u00a00m0.136s<\/div>\n<div>user \u00a0 \u00a00m0.152s<\/div>\n<div>sys \u00a0 \u00a0 0m0.080s<\/div>\n<p>&nbsp;<\/p>\n<p>\u53ef\u4ee5\u53d1\u73b0\uff0c\u8bfb\u5199\u9501\u6bd4\u4e92\u65a5\u9501\u7684\u8fd0\u884c\u65f6\u95f4\u8981\u957f\u3002\u7136\u800c\u4e5f\u5e94\u8be5\u8fa9\u8bc1\u7684\u770b\uff0c\u5728\u4e00\u4e9b\u5199\u64cd\u4f5c\u6bd4\u8f83\u591a\u6216\u662f\u672c\u8eab\u9700\u8981\u540c\u6b65\u7684\u5730\u65b9\u5e76\u4e0d\u591a\u7684\u7a0b\u5e8f\u4e2d\u6211\u4eec\u5e94\u8be5\u4f7f\u7528\u4e92\u65a5\u91cf\uff0c\u800c\u5728\u8bfb\u64cd\u4f5c\u8fdc\u5927\u4e8e\u5199\u64cd\u4f5c\u7684\u4e00\u4e9b\u7a0b\u5e8f\u4e2d\u6211\u4eec\u5e94\u8be5\u4f7f\u7528\u8bfb\u5199\u9501\u6765\u8fdb\u884c\u540c\u6b65\u3002<\/p>\n<p>\u8fdb\u4e00\u6b65\u5730\uff0c\u5728\u524d\u6587\u6240\u8ff0\u7684 Session Server\u4e2d\uff0c\u7531\u4f7f\u7528\u4e92\u65a5\u9501\u7684Synchronized\u7684\u66f4\u6539\u4e3a\u4f7f\u7528\u8bfb\u5199\u9501\uff08\u8bfb\u4e0d\u4e0a\u9501\uff0c\u5199\u90e8\u5206\u533a\u95f4\u4e0a\u9501\uff09\u7684ConcurrentHashMap\uff0c\u7b97\u662f\u67d0\u79cd\u4f18\u5316\u3002<\/p>\n<p>\u6700\u540e\uff0c\u60f3\u9648\u8ff0\u7684\u662f\u67d0\u79cd\u7f16\u7801\u98ce\u683c\uff0ccode style:<\/p>\n<p>1) \u903b\u8f91\u533a\u5757\u7528\u5355\u884c\u9694\u5f00\uff0csingle blank line for every block<br \/>\n<a href=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/04\/code-style-201604.jpg\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-1169\" alt=\"code-style-201604\" src=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/04\/code-style-201604.jpg\" width=\"558\" height=\"816\" srcset=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/04\/code-style-201604.jpg 558w, https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/04\/code-style-201604-205x300.jpg 205w\" sizes=\"(max-width: 558px) 100vw, 558px\" \/><\/a><\/p>\n<p>2\uff09\u529f\u80fd\u533a\u5757\u7528\u53cc\u7a7a\u683c,double blank lines for every function block<br \/>\n<a href=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/04\/code-style-201604-002.jpg\"><img loading=\"lazy\" alt=\"code-style-201604-002\" src=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/04\/code-style-201604-002.jpg\" width=\"591\" height=\"886\" \/><\/a><\/p>\n<p>3)\u5de6\u82b1\u62ec\u53f7 { \u968f\u4e0a\u884c\u5c3e\u90e8\uff0c\u53f3\u82b1\u62ec\u53f7 } \u6362\u884c\u9876\u683c\uff0c else\uff0c else if \u6362\u65b0\u884c.<\/p>\n<p>4)\u6ce8\u91ca\u8981\u5199\uff0c\u80fd\u7528English or pinyin\uff0c\u4e0d\u7528\u5176\u4ed6\u8bed\u8a00\u3002<\/p>\n<p>5\uff09\u80fd\u4e0d\u5199\u5e38\u91cf\u5b57\u7b26\uff0c\u5c3d\u91cf\u4e0d\u8981\u5199\u3002\u4ece\u4e00\u5f00\u59cb\u5c31\u8fd9\u4e48\u8001\u5e08\u8981\u6c42\u5b66\u751f\uff0c\u6bcf\u6bcf\u603b\u662f\u6291\u5236\u4e0d\u4f4f\u5199\u4e00\u4e9b\u5e38\u91cf\u503c\u3002<\/p>\n<p>One more\uff0c\u8d77\u521d\u91cd\u590d\u8fd0\u884c\u7a0b\u5e8f\u5341\u904d\uff0c\u6211\u7528\u4e86Awk\uff0c\u6ca1\u6709\u539f\u56e0\uff0c\u5c31\u662f\u987a\u624b:<br \/>\nshell&gt; echo &#8220;&#8221; | awk &#8216;{print &#8220;time .\/pthread_mutex_rd.out\u00a0&#8220;;}&#8217; |sh<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 -maimai \u4e0a\u8bfb\u5230\u53bb\u963f\u91cc\u7684\u540c\u5b66\u8003\u5bdf\u591a\u7ebf\u7a0b\u7684\u9501\u95ee\u9898\uff0c\u60f3\u8d77\u65e9\u51e0\u5e74\u5199\u7684\u4e00\u4e2a\u7528J &hellip; <a href=\"https:\/\/ufqi.com\/blog\/multiple-thread-locks\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6,2],"tags":[116,115,114,118,117,119],"_links":{"self":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1156"}],"collection":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/comments?post=1156"}],"version-history":[{"count":19,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1156\/revisions"}],"predecessor-version":[{"id":1159,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1156\/revisions\/1159"}],"wp:attachment":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/media?parent=1156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/categories?post=1156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/tags?post=1156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}