From 98e774688d0068f8b090b66a77af4a599a97673d Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 29 May 2016 15:07:23 +0200 Subject: [PATCH] locks: using print_with_date --- locks/locks | Bin 0 -> 20568 bytes locks/locks.c | 34 ++++++++++++---------------------- 2 files changed, 12 insertions(+), 22 deletions(-) create mode 100755 locks/locks diff --git a/locks/locks b/locks/locks new file mode 100755 index 0000000000000000000000000000000000000000..78d65ebd799983b4101b4611286201612016d83c GIT binary patch literal 20568 zcmeHvd3;;do$tAlmz&6o9A|M7lPEDE3B^l7$RuHjoWwx}Cj^pEC0Jzg_edPG0Tv`@Y>LprDcZZ^#jx3ZvAubW5;^kh+vaUkhb*Us3Zx;FnSKgmC@}u{st$u5;cKMUP zATKvL3)p!ag8BUZYXSas1^D+B;2$r*|8fC-J@_8{a?`tD1ki*fD0Rltk{OKer3r+FK!d5h@sPiRq0(U>(M?H&Pl|e7 zyAxrA+!arRqp2>DjD$jQ=1~Mz0AdN)Vf6ka^i%%cKsX9ccW*4JIDT@{^bql zXRu`}GU)P#3($~wXgcMClUJw2dF5DJWTQD&TYM{z*J2xo@&@R?2jn>K#jiRXF6R^W zCiDyP?i~Ia9xFv+zoOG~!c%DV4$w@7{AbCMw(=dB{4)#M$(GMh7@kOV?Gop+oX-NC zbpIru&jy`z|0Mrx%>>l<1^FHu-&5BvDe@Oc%)03Ng8YRxe$B#mNtNPi*!UhBpY^HJ z5*wfOs8f@TPait1vhnTDX|Ih>-#Ynhe0>iyZ;OqOhRCFAZ2YMit`O}uzRSk%vGL1n z{J4#8Z?8QzeuYiG&&IE`@o%^B*^hKOXyfzQtJ7UJzI}W@WaC$BVZi%se7=L|blAq9 zshNNe+xW9={1F?!#>W4-jgL_|lTO(9>J?4qy=3FpW~A|6Xycz{T8Fq}e6MypsN4255H0u_j5sMVei3%p>VHNVDsWxh4Gv((H0$Lejq@&8{|f z`V%k~{facZ*w{%)KSP>bYwU!iA1BQ&H8vvYBc$1t#tuv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%3jEcSPE$5>2&UU=!&VK=aiDCGy$l1_Qqk%luLVdf+gzte-2NvX8}|M~)aes|@WWCc4#;OF~3@Bt}5x&J=| ze!h6P9LV@{m!^JOK>l!G@P0 zENr*4#ajjJ6l2z3h5a)e)T z$P_6ce_H|m-Qc@XpC{|uEd%QMEoDDk*?0{jU0>_55nz#Wr( zaeldgo%;*$AEABJ!%KDTvbehcKPlxWzn?s#6T4Jmudv>lJJY?rn8B%cXh~rP98P74 za+b-}JHLP9Rn41P{4JX|AZV)u8qZR~#AL&@o0~Vau7{K@M}812{Fk;}v97tzf5pa) zTU)mIw>7V8YoR&$&2TW8ma%3gsn$2rUa$USm|q9WZ=kbTx!+jlm%)KoerT8*0EsPFr21LprFIv08d zet500lEbT@1#)LJl(nZi5ZLL==q+b5 z$tu&;xKc#>*Xsc_R6x?_3@ysCp>aa)=<|%9*4OI>KW3#MU1oty{8~=Koyg~zK}~1Y z7gV6_N}u6SM#rz%;wB)hQ?0MpA=;JT{Yo&m{&e~GEB$p!PM>=;vD?a|&q-3Bb5-qM z>wgJ6_9<0enRShWY!sy28F+5{4?xDQuh%~gEB%q24(pay`L1cDJ9G5)`(zw@lT41O z7Sva*r|G+a*!}DEloXaAm{c`b1g^R99|Dj1y8iY1d!N#OOlLrbN!Oo6;qMy&vFq#g z8U1&muGfMJ=KB9hj=o;UIixE7&Yb$o^*;jr3jEY25@Z;n*4OJtZV#A9x$?R6ze9$7PwVS-rWy~JNGDbKb^p}*x*xm_8M}YI z9(87cR4?dX+c}k^pINtBXz8D}K<29TG~~L3-M^lvo>uxgPHjNzY5D^oHgGE-ODP8Il>wo@_$ z=l_jG__UzP%ORz`oDijC-zrPNRO27J({lWD|Iy<&t2dwj+t*q8JZNf9x&HqT=MxF( literal 0 HcmV?d00001 diff --git a/locks/locks.c b/locks/locks.c index 8654b75..149a2e6 100644 --- a/locks/locks.c +++ b/locks/locks.c @@ -140,32 +140,27 @@ void *thread_one(void * arg) { fd = open(fileName, O_CREAT | O_RDWR, 0664); if (fd == -1) { - fprintf (stderr, "%s: %s\n", "threadOne, open file error", strerror(errno)); + print_with_date (stderr, "%s\n", "ThreadOne, open file error", strerror(errno)); } - fprintf (stdout, "ThreadOne: before lock\n"); - fflush (stdout); + print_with_date (stdout, "ThreadOne: before lock\n"); do { flockErr = flock(fd, LOCK_EX); } while(flockErr == -1 && errno == EINTR); if (flockErr == -1) { - fprintf (stderr, "%s: %s\n", "threadOne, flock error", strerror(errno)); - fflush(stderr); + print_with_date (stderr, "%s: %s\n", "threadOne, flock error", strerror(errno)); } - fprintf (stdout, "ThreadOne: after lock\n"); - fflush (stdout); + print_with_date (stdout, "ThreadOne: after lock\n"); sleep(30); - fprintf (stdout, "ThreadOne: before release lock\n"); - fflush (stdout); + print_with_date (stdout, "ThreadOne: before release lock\n"); do { flockErr = flock(fd, LOCK_UN); } while(flockErr == -1 && errno == EINTR); - fprintf (stdout, "ThreadOne: after release lock\n"); - fflush (stdout); + print_with_date (stdout, "ThreadOne: after release lock\n"); close (fd); @@ -178,31 +173,26 @@ void *thread_two(void * arg) { fd = open(fileName, O_CREAT | O_RDWR, 0664); if (fd == -1) { - fprintf (stderr, "%s: %s\n", "ThreadTwo, open file error", strerror(errno)); - fflush (stderr); + print_with_date (stderr, "%s: %s\n", "ThreadTwo, open file error", strerror(errno)); } - fprintf (stdout, "ThreadTwo: before lock\n"); - fflush (stdout); + print_with_date (stdout, "ThreadTwo: before lock\n"); do { flockErr = flock(fd, LOCK_EX); } while(flockErr == -1 && errno == EINTR); if (flockErr == -1) { - fprintf (stderr, "%s: %s\n", "ThreadTwo, flock error", strerror(errno)); - fflush (stderr); + print_with_date (stderr, "%s: %s\n", "ThreadTwo, flock error", strerror(errno)); } - fprintf (stdout, "ThreadTwo: after lock\n"); - fflush (stdout); + print_with_date (stdout, "ThreadTwo: after lock\n"); - fprintf (stdout, "ThreadTwo: before release lock\n"); - fflush (stdout); + print_with_date (stdout, "ThreadTwo: before release lock\n"); do { flockErr = flock(fd, LOCK_UN); } while(flockErr == -1 && errno == EINTR); - fprintf (stdout, "ThreadTwo: after release lock\n"); + print_with_date (stdout, "ThreadTwo: after release lock\n"); close (fd); -- 2.1.4