{"id":983,"date":"2024-02-28T22:31:21","date_gmt":"2024-02-28T14:31:21","guid":{"rendered":"http:\/\/blog.chxzking.cn\/?p=983"},"modified":"2024-02-28T22:31:22","modified_gmt":"2024-02-28T14:31:22","slug":"%e7%90%86%e8%a7%a3%e6%8c%87%e9%92%88%e5%9d%80%e4%bc%a0%e9%80%92%e7%9a%84%e4%b8%80%e7%a7%8d%e6%80%9d%e7%bb%b4%e6%96%b9%e5%bc%8f-%e8%99%9a%e6%97%a0%e6%8c%87%e9%92%88","status":"publish","type":"post","link":"http:\/\/blog.chxzking.cn\/index.php\/2024\/02\/28\/%e7%90%86%e8%a7%a3%e6%8c%87%e9%92%88%e5%9d%80%e4%bc%a0%e9%80%92%e7%9a%84%e4%b8%80%e7%a7%8d%e6%80%9d%e7%bb%b4%e6%96%b9%e5%bc%8f-%e8%99%9a%e6%97%a0%e6%8c%87%e9%92%88\/","title":{"rendered":"\u7406\u89e3\u6307\u9488\u5740\u4f20\u9012\u7684\u4e00\u79cd\u601d\u7ef4\u65b9\u5f0f\u2014\u2014\u865a\u65e0\u6307\u9488"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u524d\u8a00<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd\u65b9\u5f0f\u662f\u6211\u5728\u7814\u7a76\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7684\u8fc7\u7a0b\u4e2d\u53d1\u73b0\u7684\u4e00\u79cd\u7406\u89e3\u65b9\u5f0f\uff0c\u867d\u7136\u5e76\u4e0d\u5b98\u65b9\uff0c\u4f46\u662f\u4fbf\u4e8e\u7406\u89e3\u6307\u9488\u7684\u4f20\u9012\u8fc7\u7a0b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf7\u770b\u4e00\u770b\u4e0b\u9762\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void *function(void* arg){\n    int *return_data = (int*)arg;\n    (*return_data)+=10;\n    return (void*)return_data;\n}\n\nint main(){\n    int a=10;\n    pthread_t t1;\n    pthread_create(&amp;t1,NULL,function,(void*)&amp;a);\n    int *result;\n    pthread_join(t1,(void**)&amp;result);\n    printf(\"%d\\n\",*result);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u8fc7\u672c\u6b21\u8ba8\u8bba\u7684\u5e76\u975e\u662f\u7ebf\u7a0b\u7684\u521b\u5efa\uff0c\u800c\u662f<code>pthread_join(t1,(void**)&amp;result);<\/code>\u8fd9\u4e00\u884c\u4ee3\u7801\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">pthread_join<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u51fd\u6570\u7684\u51fd\u6570\u539f\u578b\u662f\uff1a<code>int pthread_join(pthread_t __th, void **__thread_return)<\/code>\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u4e8c\u7ea7\u6307\u9488\uff0c\u4f7f\u7528\u4e8c\u7ea7\u6307\u9488\u7684\u610f\u4e49\u662f\u4e3a\u4e86\u5728\u8fd9\u4e2a\u51fd\u6570\u4e2d\u80fd\u4fee\u6539\u5916\u90e8\u7684\u503c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe\u8fd9\u4e2a\u51fd\u6570\u4e0d\u4f7f\u7528\u4e8c\u7ea7\u6307\u9488\uff0c\u90a3\u4e48\u5916\u90e8\u4f20\u5165\u7684\u503c\u5219\u5728\u51fd\u6570\u5185\u90e8\u662f\u526f\u672c\uff0c\u526f\u672c\u7684\u4fee\u6539\u4e0d\u4f1a\u5f71\u54cd\u5230\u5916\u754c\u7684\u503c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u865a\u65e0\u6307\u9488\u7406\u8bba<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\u8981\u660e\u786e\u4e00\u70b9\uff0c\u4e00\u4e2a\u53d8\u91cf\u5b58\u5728\u4e24\u4e2a\u610f\u4e49\uff0c\u4e00\u4e2a\u662f\u5b83\u7684\u503c\uff0c\u53e6\u4e00\u4e2a\u662f\u5b83\u7684\u5730\u5740\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>int *a = &amp;b;<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u6837\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0c\u53ef\u4ee5\u77e5\u9053<code>&amp;b<\/code>\u7684\u610f\u601d\u5176\u5b9e\u5c31\u662f\u4e00\u4e2a<code>a<\/code>\u6307\u9488\u6307\u5411\u4e86<code>b<\/code>\uff0c\u90a3\u4e48\u4ee5\u6b64\u4e3a\u57fa\u7840\uff0c\u6765\u770b\u4e00\u770b<code>(void**)&amp;result<\/code>\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7531\u524d\u9762\u7684<code>int *result<\/code>\u53ef\u77e5\uff0c\u8fd9\u4e2a<code>result<\/code>\u53d8\u91cf\u662f\u4e00\u4e2a\u4e00\u7ea7\u6307\u9488\uff0c\u90a3\u4e48<code>&amp;result<\/code>\u5c31\u6709\u70b9\u532a\u5937\u6240\u601d\uff0c\u5982\u679c\u52a0\u4e0a<code>\uff08void**\uff09<\/code>\u5c31\u66f4\u52a0\u4e00\u56e2\u96fe\u6c34\uff0c\u90a3\u4e48\u5982\u679c\u5728\u6b64\u65f6\u5f15\u5165\u201c\u865a\u65e0\u6307\u9488\u201d\u7684\u6982\u5ff5\uff0c\u5219\u4f1a\u5f7b\u5e95\u89e3\u5f00\u8c1c\u56e2\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u8bf4\u4e00\u8bf4\u6211\u5bf9\u865a\u65e0\u6307\u9488\u7684\u5b9a\u4e49\u2014\u2014<mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u4e00\u4e2a\u6ca1\u6709\u5b9e\u4f53\uff0c\u53ea\u5b58\u5728\u903b\u8f91\u7684\u6307\u9488\u3002\u6240\u4ee5\u8fd9\u4e2a\u6307\u9488\u53ea\u80fd\u5b58\u5728\u4e8e\u8111\u6d77\u4e2d\uff0c\u56e0\u4e3a\u5b83\u5728\u73b0\u5b9e\u4e2d\u662f\u4e0d\u5b58\u5728\u7684\u3002<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7406\u8bba\u7ed3\u675f\uff0c\u5b9e\u8df5\u5f00\u59cb\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>int** = &amp;result<\/code>\uff0c\u6839\u636e<code>result<\/code>\u662f\u4e00\u7ea7\u6307\u9488\u8fd9\u4e00\u70b9\uff0c\u53ef\u4ee5\u53cd\u63a8\u51fa\u5b83\u7684\u865a\u65e0\u6307\u9488\u662f\u4e8c\u7ea7\u6307\u9488\uff0c\u90a3\u4e48\u8fd9\u4e2a<code>\uff08void**\uff09<\/code>\u7684\u5f3a\u8f6c\u4e5f\u5c31\u53d8\u5f97\u6e05\u6670\u4e86\uff0c\u4ed6\u5b9e\u9645\u4e0a\u5c31\u662f\u5c06\u865a\u65e0\u6307\u9488<code>int**<\/code>\u5f3a\u8f6c\u6210\u4e86<code>void**<\/code>\u7c7b\u578b\uff0c\u7136\u540e\u4f20\u5165\u51fd\u6570<code>phread_join<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u7ed9\u51fa\u4e00\u4e2apthread_join\u7684\u5927\u81f4\u6a21\u578b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int pthread_join(pthread_t __th, void **__thread_return){\n    \/\/....\n    *__thread_return = return_data;\n   \/\/....\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u4f20\u5165\u7684\u6307\u9488\u88ab\u89e3\u5f15\u7528\u4e4b\u540e\uff0c\u5c31\u6210\u4e3a\u4e86\u4e00\u7ea7\u6307\u9488\uff08\u4e5f\u5c31\u662f<code>result<\/code>\uff09\uff0c\u8fd9\u4e2a\u4e00\u7ea7\u6307\u9488\u80fd\u88ab\u7ebf\u7a0b\u51fd\u6570\u7684\u8fd4\u56de\u503c\u8d4b\u503c\u4e86\uff0c\u6bd4\u5982\u8fd9\u91cc\u88ab\u8d4b\u503c\u4e3a<code>return_data<\/code>\u7684\u5730\u5740\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\u51fd\u6570\u7ed3\u675f\uff0c\u6b64\u65f6\u7684result\u7684\u865a\u65e0\u6307\u9488\u6e21\u8fc7\u4e86<code>(void**)&amp;<\/code>\u7684\u5f71\u54cd\u8303\u56f4\uff0c\u8fd9\u91cc\u5c31\u5f15\u5165\u865a\u65e0\u6307\u9488\u7684\u7b2c\u4e8c\u7279\u70b9\u2014\u2014<mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u865a\u65e0\u6307\u9488\u7684\u4f5c\u7528\u5468\u671f\u53ea\u5b58\u5728\u4e8e\u5f53\u524d\u6b63\u5728\u4f7f\u7528\u7684\u51fd\u6570\uff0c\u4f5c\u7528\u57df\u7ed3\u675f\u5219\u4f1a\u574d\u584c<\/mark>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u627f\u63a5\u4e0a\u6587\uff0c\u865a\u65e0\u6307\u9488<code>void**<\/code>\u574d\u584c\u6d88\u5931\uff0c<code>result<\/code>\u91cd\u65b0\u6210\u4e3a\u666e\u901a\u7684<code>int*<\/code>,\u5b83\u7684\u503c\u5b58\u50a8\u7684\u662f<code>return_data<\/code>\u4e2d\u5b58\u50a8\u7684\u5730\u5740\uff0c\u6240\u4ee5<code>printf(\"%d\\n\",*result);<\/code>\u5c06\u5730\u5740\u89e3\u5f15\u7528\uff0c\u5f97\u5230<code>return_data<\/code>\u4e2d\u7684\u5730\u5740\u6240\u6307\u5411\u7684\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u8fd9\u79cd\u65b9\u5f0f\u662f\u6211\u5728\u7814\u7a76\u591a\u7ebf\u7a0b\u7f16\u7a0b\u7684\u8fc7\u7a0b\u4e2d\u53d1\u73b0\u7684\u4e00\u79cd\u7406\u89e3\u65b9\u5f0f\uff0c\u867d\u7136\u5e76\u4e0d\u5b98\u65b9\uff0c\u4f46\u662f\u4fbf\u4e8e\u7406\u89e3\u6307\u9488\u7684\u4f20\u9012\u8fc7\u7a0b\u3002 \u8bf7\u770b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,1],"tags":[18,33,22],"class_list":["post-983","post","type-post","status-publish","format-standard","hentry","category-c-c","category-learning","tag-c","tag-linux","tag-pointer"],"_links":{"self":[{"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/posts\/983","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/comments?post=983"}],"version-history":[{"count":1,"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/posts\/983\/revisions"}],"predecessor-version":[{"id":984,"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/posts\/983\/revisions\/984"}],"wp:attachment":[{"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/media?parent=983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/categories?post=983"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/tags?post=983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}