From 9fb1d459b50bc14c7ac56d9fd94b4b8485620730 Mon Sep 17 00:00:00 2001 From: chyyuu Date: Fri, 3 May 2019 15:53:02 +0800 Subject: [PATCH] add pthread testsuits --- testsuits_alpine/pthread-cond | Bin 0 -> 13992 bytes testsuits_alpine/pthread-cond.c | 77 ++++++++++++++++++++++++++++++ testsuits_alpine/pthread-create | Bin 0 -> 18976 bytes testsuits_alpine/pthread-create.c | 48 +++++++++++++++++++ testsuits_alpine/pthread-join | Bin 0 -> 19016 bytes testsuits_alpine/pthread-join.c | 37 ++++++++++++++ testsuits_alpine/pthread-mutex | Bin 0 -> 18960 bytes testsuits_alpine/pthread-mutex.c | 42 ++++++++++++++++ 8 files changed, 204 insertions(+) create mode 100755 testsuits_alpine/pthread-cond create mode 100644 testsuits_alpine/pthread-cond.c create mode 100755 testsuits_alpine/pthread-create create mode 100644 testsuits_alpine/pthread-create.c create mode 100755 testsuits_alpine/pthread-join create mode 100644 testsuits_alpine/pthread-join.c create mode 100755 testsuits_alpine/pthread-mutex create mode 100644 testsuits_alpine/pthread-mutex.c diff --git a/testsuits_alpine/pthread-cond b/testsuits_alpine/pthread-cond new file mode 100755 index 0000000000000000000000000000000000000000..f24440be05659d37b8d974d41873b3034719910a GIT binary patch literal 13992 zcmeHOYiu0V6~1e;;E>p{(ooW-z$)N2iO9wdc@eU(#&t3wK{6qsDc~;a-F3WlAJ*;| zHffcbS|FBXD+3Zr_<^FT(EMnmNEK32s@BLT4MM6yQ6&E;s#RfiSEh>T3nN-jzjNoD z$#|MYRfYO%t~B%A^PSh7Gjqo?p1VKj-M6bL5Kz*Z)!mAu3+*-&Wks!%JAkO#uCB-a zM)hTNE#zx7XX~RjKx?zhFR~$udtn8vDOmR6 zX&Mlkpy-`^A+1)*gMDOxCg}E~p-gSiYBd#Ej8c~n=M_IH2l>sj-#q&Xj&eRhsb}Ae znWVZTL)f8takEV;L8;*b@Z*xP#pi>RZ$Ia2bbM?1ybAKL)y7PEU}Gk^Av;pcY$$Et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3p_UuJxr(Hpm+9JMvOdwO<+)^=xx)45b=dw5g0bDa&!qq)P@ z0F(+Bhl*ywj1QN zH+(pc4%P%?uh;j63;AT+jH_^Jh!@TdB@sj<6;7D>LJ`p!j^yImbON$=8Yn`Q$Y-;u z9Q~8w3utux(xoidWuxCKNGh3EBGdBdf8d%Df0;*usHSc*59In~THS;WjY0fno(Uf3 zgftzgEBmiTF2rBvncz74dB-pLx3T}dY$x+paLVOR z>*T%T?*>O>lKYJOUP4grR~*K +#include +#include + +pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t condition_var = PTHREAD_COND_INITIALIZER; + +void *functionCount1(); +void *functionCount2(); +int count = 0; +#define COUNT_DONE 10 +#define COUNT_HALT1 3 +#define COUNT_HALT2 6 + +main() +{ + pthread_t thread1, thread2; + + pthread_create( &thread1, NULL, &functionCount1, NULL); + pthread_create( &thread2, NULL, &functionCount2, NULL); + + pthread_join( thread1, NULL); + pthread_join( thread2, NULL); + + printf("Final count: %d\n",count); + + exit(EXIT_SUCCESS); +} + +// Write numbers 1-3 and 8-10 as permitted by functionCount2() + +void *functionCount1() +{ + for(;;) + { + // Lock mutex and then wait for signal to relase mutex + pthread_mutex_lock( &count_mutex ); + + // Wait while functionCount2() operates on count + // mutex unlocked if condition varialbe in functionCount2() signaled. + pthread_cond_wait( &condition_var, &count_mutex ); + count++; + printf("Counter value functionCount1: %d\n",count); + + pthread_mutex_unlock( &count_mutex ); + + if(count >= COUNT_DONE) return(NULL); + } +} + +// Write numbers 4-7 + +void *functionCount2() +{ + for(;;) + { + pthread_mutex_lock( &count_mutex ); + + if( count < COUNT_HALT1 || count > COUNT_HALT2 ) + { + // Condition of if statement has been met. + // Signal to free waiting thread by freeing the mutex. + // Note: functionCount1() is now permitted to modify "count". + pthread_cond_signal( &condition_var ); + } + else + { + count++; + printf("Counter value functionCount2: %d\n",count); + } + + pthread_mutex_unlock( &count_mutex ); + + if(count >= COUNT_DONE) return(NULL); + } + +} diff --git a/testsuits_alpine/pthread-create b/testsuits_alpine/pthread-create new file mode 100755 index 0000000000000000000000000000000000000000..d1fc403dabf3bd4c0ffd2f55931bdf5ae95f8fdb GIT binary patch literal 18976 zcmeHP4{RIPd4ETWGA-G%Y}vJ4r|s2=Qzt7a$#$G5sT|6(?9*l^{v#!B)8ImpCy6OV zvPUYF9RyRYZiuP~RWWSMimu6)V)GEJ^%9`<)?sz)v};iyP!j_ciUBjWW|QG{QQBp7 zkS^Tsd+&XxG)lPq_Qu_xt|5_r7~~eD~+mZx0+j95M{SB`gjI;+}3-NJ0yq z?b8*Igt$wzV82s*P&9*Yl9-Yw6oFKgu23b7YCH@|b_FdD((PK0Dff^l+0`ov>JSQ3 zp~pdX5fW%VNKaFTP?)mZYtNKoAp*2O3MfqdcGQ*Sm=ufU-b!lfaX+ak+Yw84?Qx~w zexQ<0>-Ly(JdeLtN>g0Un@T@OKdfNElw)`Tb~l-X{rdE$aljK{!q#DH!}cTR<%x^)Z?yIN zeD0>}uf9%D-SPoQHr0?)9BSe3uY;F>o7jToDF9{=1plXX@IK(R+8wEbAFhLcr;h(q zz;|K`mRkXA5^KEqZ)k+qZRUGe7imWei{8I6%qgO1Y9oH431vir` zjS4%H%alZ+H10adw4K7fn!nfJ8*4L@-FeTh=BYRb>6z|9qZfggss^X>kqA8zGcmRkCe&qJGc{P!|C4ZbYDLC_^>t8 z`!rRp+1L7pPLNCCL<@a4-;>6I$m zh7q5~QH5$6s_4t|-$47}Ydhd+7_2q(uU%vq zFxY`5YxYOh{FZ-)_TOTI*556+z~k(|;>;6^qO=?Rf8{rXm>XV1(@VH9fyPDBT>iy> zmdoFwX|enkYVfxLe^-^iKLG6c`)i122d>OKaYgw%C;eT4zbF0vp7Z?uIcjqQi#Q_l zy}u6?)m}=XS0ws14?PCdnj2X1T6;``qkToIBCs=t(hC;Qnb8i&0LROfBp1B4_`jMyac!MRH8;2 zr4fNf1R4=&M4%CYMg$rWXhfh9fkp%x5%@n7fg$;d&g>Stv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7Z>%5ru?ypvkX**E+t2>`$dGaUFGV z6S!HeE(9)i`sjtN|LJzz(Lq%CuN}0;|{Lm}B!o6Yh|iYI9d)n3xHq z#HNdRdmIa4%59aowO*#JFU{4T&-yO8u`06`qk7jQ*^y#VE%9~UuFmka9a<6#+sUO> zDsOeVF2CB>$-SJQ>+hY27tc&!VGdey6&>fATvZoDd@MH^A5Rv?MLc~b2X#eDu86x% zHc6na6|yA}mqCf68XwDpEjd%z%Y@^&o0naVJL9?w<7qfyPQ>Mbhj%*uAQ&FC05jQQ zaw3ybsE8vbP|r_HIJmosr=5|>F+1rdb7PpWnw5#kEE*YcoyS;`#gi4T%c;r?2F}%N zp4yUrwcA>!+Gf5z)XEM|_|334I=?-Azo9%g>%ybDde+l-VewN8M+w*#w>3MA&>_4}E zMB5+Kdi-3G>4MLme$s>er-u^MCw@%itkb)s2pcrE(S&w*!4IO|9^hXEU(0?)+rK9u46x!K>ex5$Q4M`J z&|c8~XLam +#include +#include + +void *print_message_function( void *ptr ); + +main() +{ + pthread_t thread1, thread2; + const char *message1 = "Thread 1"; + const char *message2 = "Thread 2"; + int iret1, iret2; + + /* Create independent threads each of which will execute function */ + + iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1); + if(iret1) + { + fprintf(stderr,"Error - pthread_create() return code: %d\n",iret1); + exit(EXIT_FAILURE); + } + + iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2); + if(iret2) + { + fprintf(stderr,"Error - pthread_create() return code: %d\n",iret2); + exit(EXIT_FAILURE); + } + + printf("pthread_create() for thread 1 returns: %d\n",iret1); + printf("pthread_create() for thread 2 returns: %d\n",iret2); + + /* Wait till threads are complete before main continues. Unless we */ + /* wait we run the risk of executing an exit which will terminate */ + /* the process and all threads before the threads have completed. */ + + pthread_join( thread1, NULL); + pthread_join( thread2, NULL); + + exit(EXIT_SUCCESS); +} + +void *print_message_function( void *ptr ) +{ + char *message; + message = (char *) ptr; + printf("%s \n", message); +} diff --git a/testsuits_alpine/pthread-join b/testsuits_alpine/pthread-join new file mode 100755 index 0000000000000000000000000000000000000000..bcf7f21bfdf3a73a23397c765ff95d64febd024b GIT binary patch literal 19016 zcmeHPYiu0Xb-uI9rIw<^hbY-nWF;HfOk_v96eU@<x4C%01Ueg-2jQ&3bh*Nhl3=A;QokR1O*LQb^@oaY6nG%{)ph%2ni`MourLi zA>MxH-g}0#!`-GW@~6dKVCJ0joyWcR%$?ag!+ZJpfy09y!w_7&;$A`0^KA+VYlXj0 zGazAcw^)nwhebd%LT-?l(uWm+R+U|zO6u3R7nJ-awcbs)Xgj9dLZakXt2|2$LSZU& zKgiEV3N5>7Cp8F#DeLX}0#Yr6i~d@}Or3tzlq*4HaHXe`?$G_dtSS4ED7z3+_P89X zXgW;|LSf4JJpOheMtRv8AZ-<@V6jtE&fy98>6B^Be@!@j!@9m&{R`-RG1bi$U8&?) zS1J}v7xSs$)ZP26eS1UsY^a-SrOU7$2iePZP5%)tc-SDU1xG86e~Q1BexdYk%hfmD zA*gEU2fCq(=KdNu<)xbacYp_QxXUE~0XGQwCpGY!fme(Fr!{b^2L6{d@LUc22Jiq5 zclkVk?QRe<4bu%`jeVaO+U5a?H;Zi@3SeB|dPYO5uI6N6A{URutaPyupR$UXR5tpk zu&jI`5`EN)PCRNQBFU7nl9^;dOy-iALPD@h6pn?suo6((po$}-u-zlsWCkIlQxP(a zq>_)vZS#CQm4J@gMs?;2RyrcBWAR*kJee=Vb5o7MMeFwhQfnRpu z%?`ZI)-zDgKs^KX4Ae7F&pxaVN zNS>g|maddhIv*jKrvFQqr94J5O&ymOr2J`;Y09{CLCV7<)0B4Uyp-=JnWnN!^HT03 znWnHy(^5V_GEFU)CZ)U^a$>&R$&~C9^Je$Y&Do!sr91Bl3SrK?wY&%qaoj9@%5Toy zHPHQo!zEu2T4k2jZ$TKd)U%HISyFrpVwff08Y26z7h23Y-%s(vZGK^);3;3Z22Q*=6(3&ELFd&b~~>0AENweYI}re_DmMZ{7Mz5Xt~`F^?lVD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ZY;f@8z=$={+jn@tsf3x}MKk6PPB`hSlnOY+>_1-TA8a z&0>D9)&~5Jt*~SHym}+B_uy7;{jJ!|tG4IHX>u*BcqZoZk=uOr24bF+qhs#fyt0CB z+gI-g=54$cdvZhhGikgBh)}+eQ*?qkIfMu zZZcI6A-Qom1U59Dg@{egILkhUa#`80P<%o+VIqbgEQydDH;7KdM^+L^C!=5}86l(* z7TI({h3Cag-7_72&S`UTE0}-Bw>I|Y`7=}gefDYx{(WbEtm_xeIM{zdGfby- zh4fq}mi>8Vb|)~3&HiEi1HhEOU&2Hdcl+t*kX+cG=j}}Am7A=CSa7`2H%N8v|86;1g&u12LT^F$BhaQgH60#j~3`?$i3Pr3ZhYXhd7 zXZGjzGkw_Q&%fJDz@7hu%b(v1nQ}eaeO3Qc+TX4wpe;4ssYNF4`tf~9#$*Z? z@FmuLJ>LUHF?DyzL>9kJ{4=f!S!CJ(hI#fS`YrllK)I}leRkWn*6^R+r(Dk4o{Di_ zKZ?iC4yS40E+rk;f7tpEL`n(wpP#Gr-pXTFd8qTGes3(gg1g&KuPfF3-wvxd+guJV GQT!(r#~POa literal 0 HcmV?d00001 diff --git a/testsuits_alpine/pthread-join.c b/testsuits_alpine/pthread-join.c new file mode 100644 index 0000000..056ff32 --- /dev/null +++ b/testsuits_alpine/pthread-join.c @@ -0,0 +1,37 @@ +#include +#include + +#define NTHREADS 10 +void *thread_function(void *); +pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; +int counter = 0; + +main() +{ + pthread_t thread_id[NTHREADS]; + int i, j; + + for(i=0; i < NTHREADS; i++) + { + pthread_create( &thread_id[i], NULL, thread_function, NULL ); + } + + for(j=0; j < NTHREADS; j++) + { + pthread_join( thread_id[j], NULL); + } + + /* Now that all threads are complete I can print the final result. */ + /* Without the join I could be printing a value before all the threads */ + /* have been completed. */ + + printf("Final counter value: %d\n", counter); +} + +void *thread_function(void *dummyPtr) +{ + printf("Thread number %ld\n", pthread_self()); + pthread_mutex_lock( &mutex1 ); + counter++; + pthread_mutex_unlock( &mutex1 ); +} diff --git a/testsuits_alpine/pthread-mutex b/testsuits_alpine/pthread-mutex new file mode 100755 index 0000000000000000000000000000000000000000..b21743aec0a3bd6275d89aff94061131e4cf2b8c GIT binary patch literal 18960 zcmeHPeQX@Zb)UV{Q72I%DN)u(R3{tTYGuQB6eU@f>`*?EI%%28vOdUIiDRsecYEa7 z$2;ae99pdr)(3;aq8dz0nMxoVS@@sg9u*b~)?Gi6r``C|HUVdo0DikK|r z3YDy2jWqNsj8TXyr}DXru(YWPcDa%&RqTnBRLD3b zXDnB)I3+t!PMdvN)D(vDUcKa9@E{vRAc#N^fgl1w1cC?z5eOpi|1$!oYk!R) ze(j$zW<0-yD%S70*n{()U&p!geF@}BnQzD+G1vjor{xRZd$a!N?@}tDl z(D%k=$$x}+8uH$FUh-#&r=jkR1<8Mqcp94Cn3nti`0PS`4^z_5E?B*9TC@LR&EInl z6KZSb`f?2x;3fE<*6eHj!{;iSthv6=gRk8!D-fB-e9M}@^|y)KximEUP3s%)hOPR` z@b?AscjSBJE~~z1%|<>Aw!gmZo3CH54U+9l-(m6#kMn)&JK^!woAvr5{U5y&xd7aF zbZH4HF{!e11TA0PwuleL$? z!RQv61b6P4|A$!mzfeBa+<4*nu()PDFM6y@YH+n)E@{v(95 z$?G#uU6;1krR}q>?H`ftT(aht^-~2byTEGzzAnr8Dsr;w^L1)3aelGGRvNMau zY~(sJbCDn5EXx?$%=H^2m-Bs}gQWH_@(YhHk(+b43d?s1an_m(TQe*5O0<5}nt46? z`djB8d35P??Jl%h-Uw89kb(#V5eOm>L?DPj5P={9K?H&b1Q7@#@Cy`yVfp)=DSw^I z6$@rImCHMs`^-I=jbgA^E#Rj$^NCcx>L^GUyTkX>Z-+FYzxEcUSfCe{>-9;{zkIu1 ze+IPrZ}s{YK`CuhL>L#(3S+9v*u80ebOAH-JAnTZjs^IbCY_G1;~hIc*xCN^=(Kp? zJ@?;r;Evk}Ci`PJYS7zBfKH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KCC5hm^_luBFQOuOInypFJL3^IpXq);~00000 literal 0 HcmV?d00001 diff --git a/testsuits_alpine/pthread-mutex.c b/testsuits_alpine/pthread-mutex.c new file mode 100644 index 0000000..8394e87 --- /dev/null +++ b/testsuits_alpine/pthread-mutex.c @@ -0,0 +1,42 @@ +#include +#include +#include + +void *functionC(); +pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; +int counter = 0; + +main() +{ + int rc1, rc2; + pthread_t thread1, thread2; + + /* Create independent threads each of which will execute functionC */ + + if( (rc1=pthread_create( &thread1, NULL, &functionC, NULL)) ) + { + printf("Thread creation failed: %d\n", rc1); + } + + if( (rc2=pthread_create( &thread2, NULL, &functionC, NULL)) ) + { + printf("Thread creation failed: %d\n", rc2); + } + + /* Wait till threads are complete before main continues. Unless we */ + /* wait we run the risk of executing an exit which will terminate */ + /* the process and all threads before the threads have completed. */ + + pthread_join( thread1, NULL); + pthread_join( thread2, NULL); + + exit(EXIT_SUCCESS); +} + +void *functionC() +{ + pthread_mutex_lock( &mutex1 ); + counter++; + printf("Counter value: %d\n",counter); + pthread_mutex_unlock( &mutex1 ); +}