{"id":3734,"date":"2020-06-28T17:55:25","date_gmt":"2020-06-28T08:55:25","guid":{"rendered":"https:\/\/now0930.pe.kr\/wordpress\/?p=3734"},"modified":"2020-06-28T17:56:50","modified_gmt":"2020-06-28T08:56:50","slug":"thread-%ec%98%88%ec%a0%9c","status":"publish","type":"post","link":"https:\/\/now0930.pe.kr\/wordpress\/thread-%ec%98%88%ec%a0%9c\/","title":{"rendered":"thread \uc608\uc81c"},"content":{"rendered":"\n<p>linux system programming, 234p<\/p>\n\n\n\n<p><a href=\"https:\/\/bitsoul.tistory.com\/m\/157\">https:\/\/bitsoul.tistory.com\/m\/157<\/a> \uc5ec\uae30 \ucc38\uc870.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;pthread.h>\n#include &lt;stdio.h>\n#include &lt;unistd.h>\n\n\nvoid* start_routine(void* arg ){\n\tint pid;\n\tint threadID;\n\tpid= getpid();\n\tprintf(\"pid is %d\\n\", pid);\n\tthreadID = pthread_self();\n\tprintf(\"tid is %lu\\n\",threadID);\n\tprintf(\"data is %s\\n\",arg);\n\t}\n\nint main(){\n\tpthread_t thread[2];\n\tconst char *message1=\"hello one\";\n\tconst char *message2=\"hello two\";\n\tconst char *message3=\"hello main\";\n\n\tint ret, errorno;\n\tret = pthread_create(&amp;thread[0],NULL,start_routine,(void*)message1);\n\tif(ret&lt;0){\n\t\terrorno = ret;\n\t\t\/\/printf(\"%d\\n\",errorno);\n\t\tperror(\"pthread_create\");\n\t\treturn -1;\n\t}\n\tret = pthread_create(&amp;thread[1],NULL,start_routine,(void*)message2);\n\tif(ret&lt;0){\n\t\terrorno = ret;\n\t\t\/\/printf(\"%d\\n\",errorno);\n\t\tperror(\"pthread_create\");\n\t\treturn -1;\n\t}\n\n\n\n\t\/*\n\tfor(int i=0;i&lt;2;i++){\n\t\tret = pthread_create(&amp;thread[i],NULL,start_routine,NULL);\n\t\tif(!ret){\n\t\t\terrorno = ret;\n\t\t\tprintf(\"%d\\n\",errorno);\n\t\t\tperror(\"pthread_create\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\t*\/\n\tint thread_compare=0;\n\t\/\/\uc2a4\ub808\ub4dc\uac00 \ub2e4\ub974\uba74 0, \uac19\uc73c\uba74 0\uc774 \uc544\ub294 \uc218 \ub9ac\ud134.\n\t\/\/\ub2e4\ub978 \uc2a4\ub808\ub4dc\ub85c 0\uc744 \ub9ac\ud134.\n\tthread_compare = pthread_equal(thread[0], thread[1]);\n\tprintf(\"thread is same? %d\\n\",thread_compare);\n\tsleep(1);\n\t\/\/\uba54\uc778\uc5d0\uc11c  start_routine.\n\tstart_routine((void*)message3);\n\n\n\t\/\/\uac01 \uc2a4\ub808\ub4dc \ub05d\ub098\uae38 \ub300\uae30\n\n\tpthread_join(thread[0],NULL);\n\tpthread_join(thread[1],NULL);\n\treturn 0;\n\n}\n<\/pre>\n\n\n\n<p>\uc704 \ucf54\ub4dc\ub97c \uc2e4\ud589\ud558\uba74 \uc544\ub798\uc640 \uac19\ub2e4. race condition\uc73c\ub85c \ub9e4 \uc2e4\ud589 \ub2e4\ub978 \uacb0\uacfc\ub97c \ubcf4\uc558\ub2e4.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pi@raspberrypi:~\/Project\/cCode\/systemProgram $ gcc -lpthread mythread.c ;.\/a.out \nthread is same? -1235590048\npid is 14996\ntid is 3059377248\ndata is hello two\npid is 14996\ntid is 3067769952\ndata is hello one\npid is 14996\ntid is 3069673600\ndata is hello main\npi@raspberrypi:~\/Project\/cCode\/systemProgram $ gcc -lpthread mythread.c ;.\/a.out \npid is 15068\ntid is 3067769952\ndata is hello one\npid is 15068\ntid is 3059377248\ndata is hello two\nthread is same? 0\npid is 15068\ntid is 3069673600\ndata is hello main\npi@raspberrypi:~\/Project\/cCode\/systemProgram $ gcc -lpthread mythread.c ;.\/a.out \npid is 15125\ntid is 3068077152\ndata is hello one\nthread is same? 0\npid is 15125\ntid is 3059684448\ndata is hello two\npid is 15125\ntid is 3069980800\ndata is hello main\n<\/pre>\n\n\n\n<p>gnu c\ub294 pthread\uac00 \uc804\ubd80\uc778\uac00 \ubcf4\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>linux system programming, 234p https:\/\/bitsoul.tistory.com\/m\/157 \uc5ec\uae30 \ucc38\uc870. \uc704 \ucf54\ub4dc\ub97c \uc2e4\ud589\ud558\uba74 \uc544\ub798\uc640 \uac19\ub2e4. race condition\uc73c\ub85c \ub9e4 \uc2e4\ud589 \ub2e4\ub978 \uacb0\uacfc\ub97c \ubcf4\uc558\ub2e4. gnu [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[12],"tags":[775,53,776],"class_list":["post-3734","post","type-post","status-publish","format-standard","hentry","category-12","tag-c","tag-linux","tag-system-program"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/now0930.pe.kr\/wordpress\/wp-json\/wp\/v2\/posts\/3734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/now0930.pe.kr\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/now0930.pe.kr\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/now0930.pe.kr\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/now0930.pe.kr\/wordpress\/wp-json\/wp\/v2\/comments?post=3734"}],"version-history":[{"count":3,"href":"https:\/\/now0930.pe.kr\/wordpress\/wp-json\/wp\/v2\/posts\/3734\/revisions"}],"predecessor-version":[{"id":3737,"href":"https:\/\/now0930.pe.kr\/wordpress\/wp-json\/wp\/v2\/posts\/3734\/revisions\/3737"}],"wp:attachment":[{"href":"https:\/\/now0930.pe.kr\/wordpress\/wp-json\/wp\/v2\/media?parent=3734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/now0930.pe.kr\/wordpress\/wp-json\/wp\/v2\/categories?post=3734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/now0930.pe.kr\/wordpress\/wp-json\/wp\/v2\/tags?post=3734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}