From 956ddbc74b2deaa727a55e267fc9b408757b05d7 Mon Sep 17 00:00:00 2001 From: Luca Arrotta Date: Fri, 2 Apr 2021 16:06:05 +0200 Subject: [PATCH] first commit --- .../6.7/executionHistory/executionHistory.bin | Bin 23133 -> 37821 bytes .../executionHistory/executionHistory.lock | Bin 17 -> 17 bytes .gradle/6.7/fileHashes/fileHashes.bin | Bin 18897 -> 19797 bytes .gradle/6.7/fileHashes/fileHashes.lock | Bin 17 -> 17 bytes .gradle/6.7/javaCompile/classAnalysis.bin | Bin 0 -> 18798 bytes .gradle/6.7/javaCompile/javaCompile.lock | Bin 17 -> 17 bytes .gradle/6.7/javaCompile/taskHistory.bin | Bin 18619 -> 18749 bytes .../buildOutputCleanup.lock | Bin 17 -> 17 bytes .gradle/buildOutputCleanup/outputFiles.bin | Bin 18911 -> 19271 bytes .idea/.name | 1 + .idea/compiler.xml | 2 +- .idea/gradle.xml | 1 + .idea/misc.xml | 2 +- .idea/vcs.xml | 6 +++ README.md | 12 ++--- build/classes/java/main/TCPClient.class | Bin 1650 -> 0 bytes build/classes/java/main/TCPServer.class | Bin 1601 -> 0 bytes build/classes/java/main/join/Main.class | Bin 0 -> 1569 bytes build/classes/java/main/join/MyThread.class | Bin 0 -> 908 bytes .../java/main/producerConsumer/Consumer.class | Bin 0 -> 1090 bytes .../java/main/producerConsumer/Main.class | Bin 0 -> 982 bytes .../java/main/producerConsumer/Producer.class | Bin 0 -> 1504 bytes .../java/main/producerConsumer/Queue.class | Bin 0 -> 1122 bytes build/classes/java/main/semaphore/Main.class | Bin 0 -> 1320 bytes .../java/main/semaphore/MyThread.class | Bin 0 -> 1606 bytes .../java/main/semaphore/Semaphore.class | Bin 0 -> 1167 bytes .../compileJava/source-classes-mapping.txt | 22 +++++++-- src/main/java/TCPClient.java | 38 ---------------- src/main/java/TCPServer.java | 43 ------------------ src/main/java/join/Main.java | 33 ++++++++++++++ src/main/java/join/MyThread.java | 30 ++++++++++++ src/main/java/producerConsumer/Consumer.java | 22 +++++++++ src/main/java/producerConsumer/Main.java | 17 +++++++ src/main/java/producerConsumer/Producer.java | 31 +++++++++++++ src/main/java/producerConsumer/Queue.java | 34 ++++++++++++++ src/main/java/semaphore/Main.java | 23 ++++++++++ src/main/java/semaphore/MyThread.java | 32 +++++++++++++ src/main/java/semaphore/Semaphore.java | 30 ++++++++++++ 38 files changed, 284 insertions(+), 95 deletions(-) create mode 100644 .gradle/6.7/javaCompile/classAnalysis.bin create mode 100644 .idea/.name create mode 100644 .idea/vcs.xml delete mode 100644 build/classes/java/main/TCPClient.class delete mode 100644 build/classes/java/main/TCPServer.class create mode 100644 build/classes/java/main/join/Main.class create mode 100644 build/classes/java/main/join/MyThread.class create mode 100644 build/classes/java/main/producerConsumer/Consumer.class create mode 100644 build/classes/java/main/producerConsumer/Main.class create mode 100644 build/classes/java/main/producerConsumer/Producer.class create mode 100644 build/classes/java/main/producerConsumer/Queue.class create mode 100644 build/classes/java/main/semaphore/Main.class create mode 100644 build/classes/java/main/semaphore/MyThread.class create mode 100644 build/classes/java/main/semaphore/Semaphore.class delete mode 100644 src/main/java/TCPClient.java delete mode 100644 src/main/java/TCPServer.java create mode 100644 src/main/java/join/Main.java create mode 100644 src/main/java/join/MyThread.java create mode 100644 src/main/java/producerConsumer/Consumer.java create mode 100644 src/main/java/producerConsumer/Main.java create mode 100644 src/main/java/producerConsumer/Producer.java create mode 100644 src/main/java/producerConsumer/Queue.java create mode 100644 src/main/java/semaphore/Main.java create mode 100644 src/main/java/semaphore/MyThread.java create mode 100644 src/main/java/semaphore/Semaphore.java diff --git a/.gradle/6.7/executionHistory/executionHistory.bin b/.gradle/6.7/executionHistory/executionHistory.bin index 6747f8a14bb08ec1a50956ff041170aba4532049..006db8acf48496a31e27edb848d4e9fde2ec3c9d 100644 GIT binary patch literal 37821 zcmeI33vd(18GvssNX)}UgkcIpNl5}EGrO!0C7^A z&U)sg)7|d>|NHIU?*IRLwi84*^Ih$aQ2$KoS3xI&=rBq>pD>Xik_y#x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;=&8B z=9HBk?Q`(i@eNF4U$DA)4Qp79OVPU6_b@B?LWjwmvi0R(?YUfirq_$Jmrwd(!WvK; zVN$SktSA*~FJx$x#&o>Ub$VW}KW**!`X4{?%)HS8rLY=N`!x5UG};gSP_wCc=`){x zXlj2ZYyYd$rqxdV7_5xI)Kom`Y*e^GA#pg)cFI{_YrY=*$~o@;!))jF{@qWG>^br@ zJFfPXx2_h?Y&qMR6!rLOC3k|eojBX6zPQ-R0BN>@|2JP3ih4w+k}6{yvd4}qBXbYH;GwohwUdj6pSwY zN7nQj5Kr~7M;r8hwC2vAxO3jM2GgAt31{neCw#so4!s+0!i|{suIgNA?R|RUS8KXB zK+?hVHTC^RURVXW*7Od2Yja)DD-PM`iQAqB-fwx(e}%YrH#XbsF@C=# p`ONSux2|n|ZPwi%r!O-%X5;-9yx$^kIK^QzBn~QC+HdL3{0Dqck)Z$p delta 33 ncmdnHoaycs#t9;<3_u{d(eZ}(!~l)Sk`h`>{`{L=B_x~xvH%HL diff --git a/.gradle/6.7/executionHistory/executionHistory.lock b/.gradle/6.7/executionHistory/executionHistory.lock index 25fc1660df19a6424171748d9d04d149c1939b53..6003b25cf6b2e5c4e0678e4f2a9ed7752bccd0e3 100644 GIT binary patch literal 17 UcmZQx#B%@j(Si?F3=kj*06b6x>;M1& literal 17 UcmZQx#B%@j(Si?F3=qHt06aki-2eap diff --git a/.gradle/6.7/fileHashes/fileHashes.bin b/.gradle/6.7/fileHashes/fileHashes.bin index 9c1905f6c787641f693e99df291ebdf87adff2b2..5b38618419ddfc788f36a591b5c3bac19fc9bea2 100644 GIT binary patch literal 19797 zcmeI3YcO0_9Ki4HqAZFkqe+u`l!!!RsL%}>vBlb5iwH?QB3X%yN2-YoO(nZZ5ws0P z*m$-@TT&&GNu}Zu5h9|5cqJqi@1dnLnyDz=>)bP$?)}uSo&TNL-8;X%zkBxl_RfCU zd$>u~S37vmxQqC1ObZRy2B>--`b~NRG}8|Ms_7W5jvIn5PPN z?UT;DutZ$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Z_vfPsPG;zq?E;u{S-#5X&7Oke~6 DR(uxV diff --git a/.gradle/6.7/fileHashes/fileHashes.lock b/.gradle/6.7/fileHashes/fileHashes.lock index 73626d62011d0364eed1646de55c6b6a8c53d75a..e1c2d55b89a02a9aeb675b966c9c84b41b1ba939 100644 GIT binary patch literal 17 TcmZP;>bX^K)h4}&0Rq$jD^~-a literal 17 TcmZP;>bX^K)h4}&0Rs2{D?bB< diff --git a/.gradle/6.7/javaCompile/classAnalysis.bin b/.gradle/6.7/javaCompile/classAnalysis.bin new file mode 100644 index 0000000000000000000000000000000000000000..ba7436ee84478a68d42902afd9273664906afb93 GIT binary patch literal 18798 zcmeI%F)ssQ9LMoT!y*zETw)TDAT)xpLoWD^rY+TwN!e4ZoZh;nWFoD zQ1R{`j~l0DlP{)RetWgu8D02I+kfNo^uX%F)7{pf&3%_I)pmB%6XCVZ-(2qQIK>Ec zWnJ@9wWIJLILt)%Ws+eRy~f^-GbI`=CUSxrgY6o{jlD&=_9n+$d^sVbq!0k JX>^;Z)M literal 0 HcmV?d00001 diff --git a/.gradle/6.7/javaCompile/javaCompile.lock b/.gradle/6.7/javaCompile/javaCompile.lock index 35ba9bf0432ba916e33f6c5a856b4fc87dc462c6..08cc0b182a61abc80fc4680c6cebd2f7d7eeee1d 100644 GIT binary patch literal 17 UcmZSHvGGIQD}xDJ7$86t07AM2P5=M^ literal 17 UcmZSHvGGIQD}xDJ7$ATd079q*JOBUy diff --git a/.gradle/6.7/javaCompile/taskHistory.bin b/.gradle/6.7/javaCompile/taskHistory.bin index 370e64289da699237ab29d76541262222e7e3cdc..5b6be10dccac7a7a3c180e10f272d4805fe7d8b2 100644 GIT binary patch delta 144 zcmdlzk#X-N#t9;Vj0|Al;RvLvfLL*(;urDBk`mgCyEnT^lo`Yt0|hIAxDbTTGrCyC z_>?9m#)Rf&Dx@le=NDzi1Z23x1iJ))u&$ATkztHaVv-S<&~>dy%q_@CEsjYl&CE%O eNzO?uE(Y?l63Y@}auYN2CMrryUgyEXSO);NbSkL; delta 32 mcmdlxiE;Nt#t9;<3_u{d(eQ=%LxFGN^{*$OT0|eLs05r!0Q2+n{ literal 17 UcmZQ>xFGN^{*$OT0|dwc05qorF#rGn diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index f205b0ddfe9c49ccd03b257269eef4658d48a994..e492cc146e32be5d9e2c086f4083fa9a005f9483 100644 GIT binary patch delta 527 zcmcaVneq5E#tkMCj@nIcm(07!-M*3m47^SMLqV&k_RbPRuD1|z&*?DnDdj$5ydLEq z5OJ@@$*vL>0yE;CcbClZwS@}iPcD^E5Ln*NFTc0RQ%-Ry%GuRhYG%hDZVVR_5>$S#}|mW=l#i7B?1KA zZeHCKaMl!N!tKejk^utD(O*BFGk^OHqS9M=a;l_)0FTGA|Gc_=2YtOm83g@BXqLaS@O^Ech&b|0@vm!*$^W$Vy zDGQs@Pt`riS*1l#m9a1rDwSO)T#LPR04nYc6Nk|Z3@nlx6@Q2?G!WVB=rNCRvcG5g UAXb_D!9xg0dq8P%004K=9smFU delta 93 zcmX>;jq(0u#tkMCjN+4hB_t--N*GK&3Z%aR=}<|D$#W$=CjSNESSg9gy+C|bN^&xr owEkpYX^F{Gr41(El{Vn{4+RViOqLrJe~521cp$pj(PJJX0B%qvMF0Q* diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..433ed8a --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +setup_SDP \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 61a9130..fb7f4a8 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index ba1ec5c..611e7c8 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,5 +1,6 @@ + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index cba2c9c..7bf9a2a 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,9 @@ -# Setup test SDP -This repository contains a simple example that enables you to test if the **IntelliJ** IDE works correctly. +# Lab2 Examples -* You can import the project directly from a **V**ersion **C**ontrol **S**ystem, by providing the following URL: -https://ewserver.di.unimi.it/gitlab/riccardopresotto/setup_test_sdp.git +* Threads Join - +* Wait & Notify -* Otherwise, take care to import the project as a Gradle Project - -* The testing files are located in the directory: *setup\_test\_sdp/src/main/java* +* Producer-Consumer diff --git a/build/classes/java/main/TCPClient.class b/build/classes/java/main/TCPClient.class deleted file mode 100644 index fb2030595ea89798deb9a5b050a65942ae1102c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1650 zcmaJ?TXWk)7(MIQmaV9{IL*bOK)4i~w5g#4C{A0b-Gl_33wD}fTA+%(c2sQ1Bg=t4 z@j`zPeXwW93_pM$)#0qfPStE4o35q42gay( zYIOuAi${gSLerAAw@HbXY1sk`nMcK^=9!sonsy^w_FT(uZ2C)>ZsSZ~?gCgK(V>X6 ztNx0wxeLs+oSId)WUV~n>6X3iI;{sC=?W|bYg$e=->uiBD{Ccb)}+h0jH(}D*{S{_ zJ%QPPX-h8~m`Is)y55mfmhPF-S{`ZLH$C&9>$STc^N?mssRgSJx%$>`RoV6|$L?r2 z5YWp`*R9HJOVw^_RGu3uB?E8Z3Jc_?_gbU^=^?Odk5&w_&~RwrJCu|{Sq(>QmCqih zA&_jUR-HN>Pf;GQC_};j=3(F%4;ATq0~P#W;1M1REc*0N+wxtj$r>8?5kINnX9G|0 z*no)>169-nE^U_%_EySUrQ@wqZbgGMP*-3>C7K+i&;E_I4^E!SDjP93HjRq-3bFjG zD6Jfi;xp=B@&!8`29mTWPP3#KQ=eO^>x- zL6p!Gg+f8HupylgK$!%0RZX2afy+ZuI53`5v)z_9OTB(U+=K8!9)p%q`bwtoe{jNc zg0smz`>ShtGXKnzJk#?REyJWHoGyDd?!qC@_4rf-z2u$_nFX}AA~o5)SheYNBvz2- zMW=odK0FN&c$2d%--7ShS|8$1AAXBt+&4z?Hs?k_pu{`;O5$C-M-e)UMZ|cq0ng77 zshne?@&eI5VtvH-&!JUPiP`1neI#?ybLf?Hw1>$)j9hHUR+dWvKNnx`VXBxWHeKms z=2{Q4GkOoH9_D(uoQ@OSdx7}@oLV4$osSPMDxsxu@HZJUcn7C2#h_>L0cSTbk6Tzo zfmPUH@K1=;nab~YAAjJgpXg4I3@umbzk@sU{E*4liDo#9P^W`ctnn{m1rpbA9Z@Pj b#5%_qwezg!8jJT4{iF2!n9ohlBlzTBc@LCa diff --git a/build/classes/java/main/TCPServer.class b/build/classes/java/main/TCPServer.class deleted file mode 100644 index f81e36253e1100b775bf383b87e96b8eb2055fda..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1601 zcmaJ>Yj+bx7=9*Avh8+z32kXp@UEBwZM;O(6j2(eRMHkmC`MGAZic#$?B;AIMg8t? z@uSBt$vNa4e}Ml<@R`kR6^=P4@6NpM^WL6$Xa0Kj^iKcTDnzH z;fV@28KNmYU*L4^e)*9+k@<%7kMb2Adj8R-NipvRzOP*E1%4%PA1f`8=_7rm^L-V= zIG(>92F+5#Q$8UpeTWz2x7rUMs!-MMC|QpZP6usW4Tiwg5%8MSa=)!xZO!aTHcf3Z zJUS6rcu8pjvu>2D!hFhiqn=-AfWEG5d0IBSUsQbzoq3`fZqQW2j+SE`MZ}EynyF~% zKHinBh(jK*fPMWZSG5cw#}>-mSAurvs%_5@KRe=f!&Kv71zCZmsIrK#Sa@UHb+Cth z@*g2y;7cGoH0<~zYWiGSxaHtB?wBwYBdX+mi2g5|4({T>fbKc?8a09C2pK!=t+vUfO8;k`)WI;J{Ur3X+WJ{5z5+`xOT$)DZX-BWcpaztqM2WUe-1GOR=LXa zEBH;F??U_$na@zBBV`h2xpw*hyn5r zZAqdp;Vrz)!VAa|d5*2J0pfG~7O7doc{Y5T@AU<)63kU){B>5aL4*zQ%oJgfx%aqF O68k>?A8?((hyMUpAc^S! diff --git a/build/classes/java/main/join/Main.class b/build/classes/java/main/join/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..2946019686eaf577e2b43de45880ddb9d13335a0 GIT binary patch literal 1569 zcmah}U2_vv7=BK&&8FKeEolkgxW%soO5z8KwzXQ3N;NH<RG|PLrkCn(WriDbh&NyECL-ao|4EUVgBux~@%VCemA3n@(K!(>0E@J<@j7T(2sS~D|%_i!p6{t?fn+YfEMS}us;tRo$FWFecCnhf2C}TJw2F6X^0w=&x~}h3 z$hLB;1rt|nEaR$;Ygl2XHm>7_jZg7eJBz4oG5Iz=*V+At%chc{b}5i23!!qpmY!m> zom)ZZ$W9iH3Y=S0ik-Y4_ddt#Qin#yeu5NtAXYmB_0xX6iCoNHI= zL5qX;syTie+NjRw&`#r@uOaPq^3UeFN3LC$9^#s8F1U9XosX2s8GdvaZQFMzFVGh? zgjSkDjNt(PJ@hXD5{^S$5A#&yF1Yud+JSf&T_53^ij*dfQnq6Q9K&&*`f&o!(Fwug zDO(wvoR2ZBjgV`sdH+&sf_S z7~h7yaOM{b3jBmDg?$3QV`#$A#={Su{-q7~(@^i3{{xJ)0HZY2l^D>K%wj)R3uz2s z7=tW)A5QYmFHgD1yK@-fiy6fg5_F9e-6T0RR(F@^?^yr$tojGmteLn7lUNfD=`@hx z%}G2@4i?G63wV*byB&$F;3d3FR2uh?V?0h1zQHM+CVS)5YhGi`8EOjDj3M;|852bl huZTxD_87K_S0CZ%V~oZEUZa^o;OqR(QcmEFzX99hY}^0< literal 0 HcmV?d00001 diff --git a/build/classes/java/main/join/MyThread.class b/build/classes/java/main/join/MyThread.class new file mode 100644 index 0000000000000000000000000000000000000000..dff7bcaab0e7f2ef5971449a0b71b8c0525d51cf GIT binary patch literal 908 zcmZWo?M@Rx6g{&oY`ZQkEubi(EsB-`tsnRaniwMq28^+U-!9z=43^nuJ2mhCJ`2Aw zT8%$^0H4ICP|s|OLd<3-Gxy$e&$(xIfBgFP9l#QvcN*+`!EYDjw!g zwYhm03m!69%%J9??&6j}D%PPuaeXg%AJn@>wd!vI9Y*`h0>djxEAv!fqVj)wZc8Bj zJPM^ieqCw#s=L1}e%YNNa^~<;pT2EgOEHTwlcb! zYsI#8%>{RC&!>mikXyYdm~;!qF6Q-##e-49>k9wD=_&_mWHSTlS~ z^f;zbB4Y}ce}+3ywY~gtvQLwtMBXyFW^oCNxSVJzvA#@|7a6m&)CTJKS7C}Zf=F;$ V=QrVwiz}4t;%b_S5)%%}e*iqgwY>lU literal 0 HcmV?d00001 diff --git a/build/classes/java/main/producerConsumer/Consumer.class b/build/classes/java/main/producerConsumer/Consumer.class new file mode 100644 index 0000000000000000000000000000000000000000..8d4380cff125d333e16aad1548d4d12f19d7ddc7 GIT binary patch literal 1090 zcmZ`&YflqF6g{&oY`ZK}7s^8vTNNzjQ6Ko=;R8tgRG&2@d@&i?2`;p|WxGq_FY>cS zN}`EB!2jb{^~|HjUmivbJIcrvlhRKY0P2X z#DWDA(@nYd@-zChnWq#`9SUTy|{Evl+u)Aw3YLj|SRI^)#{vt5-thkbXSW2Bn|_U?nX>Dt7g1wJ1#jg} zogSy`S7m)m2Cm+BoyqXM+Y*@UMLemMwTJ_OL=btj1x+zn31xNvxombp%xdRe0@-tl z)fr|(wOVqQRag~23aaXvt4kU@Az9Q4*vMka#xO=~T!drdfsKb)wvj{L#EOkotO<<$ zE7nHj)@v%DWEyQTXX6p5o4t~22CA+OW$4rQ1j{C#+E_5BfNMW|OacAHwA6lVmP*gu6Nw#y^^-Hff0wD)M$%Y;T z*=#D0V{+ag^ip)yU}7rtJJTdE9ADrpG@H`YM0F2&j&=sD4F()7Jzs&N`@l6pe-@*( zW87`?M1pIkcnndTJAzT1KSJUYT?WQ!9VBT}v}ykIn;F0aJ-JRAE@6^80>tnl{<_R8 zg9KMF)umaF_rOrG_yvhJl5O;T{QZ-s6ERCa&uI*eY{%b2UF56r8Ab&u^If=iOfwjm z`HcQ=Ft?A9a?)*B1UI-i12l8|w_&$2czPKt&Kkiq70^_p9hAS9n87t_#P@;gj2gJ{ E2jax+XaE2J literal 0 HcmV?d00001 diff --git a/build/classes/java/main/producerConsumer/Main.class b/build/classes/java/main/producerConsumer/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..7c87885d1ee0c579c875527e5f961084a20dee0c GIT binary patch literal 982 zcmZuwU2oD*7=8{ES~@m1aAP>#r&Gqp&`rG<#)~b{UBLWcStPqKr8KMr3YOL@{ZZaX zB8fl1A7y+_83EJv;+*HaU*~zB^Y+i*U%vr7#|s@x$g9}X5s`aA!-ft8`x>@1Y^ylX zu%ja(4ZA9eI_7aGmy(L7DxL|%U)hfBy%vb(_pSt#vtH8@NL6gdy70RV%e^!j9a_?r zo@sQh4A++DTchIL*aLxVrSJBdzG=BFzH4EqT68ITdkg&Y$WGLv<~0h5~r7N^o&-nf?0lsU&qJ}<9a z4po+<{!4n-Xj`TyP|Sx#4$Cu^Pl}(NjsNI7j(pkRSz-gva6N2ck>e%52si=AaJ|P< ziM!w)D-0oi1ny<7@xU0x3UP8AfGk#dN+5^(v@ltuIG!qP-$#hlhlo~2Q0nQ}{t)qM z096Su0;oxNqKuHJr*-1FlURV00gjI_Uq2XP;U`iO7N;<$%;4Azj*sz_^bx7D6KJHL zA+dF$0tvr_j#JE`O8+PRFik9=j}*R96WQSTxCyM`0Z$ryJY+6M8EtG}lZvh5GZoxK dl=W)ZCQ?}SEq3sT_no4QT_P#kV^)aZ$v-~`*VzC7 literal 0 HcmV?d00001 diff --git a/build/classes/java/main/producerConsumer/Producer.class b/build/classes/java/main/producerConsumer/Producer.class new file mode 100644 index 0000000000000000000000000000000000000000..6d346b3304e8c2e1f5348edd569ab3798813d841 GIT binary patch literal 1504 zcmZ`(ZFkf}7`?MEO&U`w+ij_U7!hSReOai0NGl>MXkiP5Ero&tX?9Kt?j|9daNrm5 z6+Lv}=s6z!>M!v(_(8mrP3dAw&*@BN=9&B4d!J|auYZ629l#0PH!z8l!`O#YYWPA8 zrwtBY4&w~wH7pp=a8k!tYCfyuYc-!U@D0uzsN>rrVfdH-+rR}})bO2w628~5sN<3f zy{w_3VM)Ukft=S8C^a5BkDXfE@i%JCIP(0Bd4b}iL?%*TvJpl>D{*C15BzS@kx}iM zI$?tLl|m5B8ep}kXh%sH%hrV_t_))@@RgvB z>~@_E29Gpj$Ng!^3Dc~pVOQxSLozo6%9ZK>;v3(LW{^a#yyz(fBU_wimBS`1R81Vh zM<({;fQf_n(8O`fX;?OK4c7(s{l60D6R+J;77rGMsa&iPRhCxy49< z!(83wex7sLehFdcH<7caHj%fdH&OUGz4ZylJ!y=N0?~(|;|TYx{ylt(&$uE&nop!( zN0~9l3>8$fJbyA;<*C~}6dS)_=r?F9J(xX=aJRtKo-#&X zVed2OOVd4!J$wBJA?I)!^OTl{qIZ~-024)wz$V!_?B#hmjaa}K&SCrwO#BQOm|WIDL(kh zt0r0!O^DC_6d!#y;+gFxfHs@V-nsYOGv}U}AAi2?1DMBy7!t_n$i@&tCW<(6DwQT)&GW$c^x-3^jEx%4Iwp*ls3(6Gw-=pBmYoJbEjmr-GYW_ z*{a*7>q(&@+Y3|dCL5+*&zD_k+4aIA`}&KPZMlmY!kO%vhRBjrBSWHO+2X0!tO&Vk zRvOFCSTm)i_CYe@zP8#L#!4;e)V!*YOOD<4nnLDZc)}B;54Sv*qBH*=u1?dN zqTM#@KD|HIQFRpKnp><5XM%x_S2dOcrLsJUjT0`w?EcMRr})RLkz z%9}C9oVM$=+c)k;VmIcQMc%BBHDNB2jTfej}vg(sLbCx|-%Pvmsph E3-R;lCjbBd literal 0 HcmV?d00001 diff --git a/build/classes/java/main/semaphore/Main.class b/build/classes/java/main/semaphore/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..6e7db4067f6e83ba23a282637a564fab022f557d GIT binary patch literal 1320 zcmZuxS#J_i7(EvTE}c#nyJ^+B)QzsV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Fj>OAEsj8WS3Jb?)~IEf5$lrKVMz?E06t#@h7nEK1Mn_F@Rlo1ap8BS%>=pG6S5XCN;q1F@94czvGilkDPR} z>LI-y=AGkbLNS}w?9EfVK;2pOV(3aP?Pq9P!K!9(aahw~ e#6|iF6m`eOzf5LWc!jT?g;!HFyhek8*Z%{PO<>^w literal 0 HcmV?d00001 diff --git a/build/classes/java/main/semaphore/Semaphore.class b/build/classes/java/main/semaphore/Semaphore.class new file mode 100644 index 0000000000000000000000000000000000000000..46ce2ecb0fd05ade46b044b47cf90acbfbaf1f36 GIT binary patch literal 1167 zcmaJ=+fEZv6kVq+owf`u6j~HeiZ@Du76q>$3JBVyil&5wH;48}2iuuuI#u`_6BC{_ zQW8!40RO~Ce?VNPtrP<>liBCYzOA({^W*o|?*QiTEQBb=gXlw2iHRUmnA9*8LKnsZ zm{w<6iA(@9>bx1kEzGK@ISsc%2;+|WxU1owhWi4+im~^iUfGt8fXMROEjiLC*0Pp> zf5Eg&cTvEX%ua0bSh0&zAd)jJ*^1dPw#(E+b9TWfZyJuNzS~NlTQX|`v0P17jB3et zWG4UjHZR~Mut1lzTm|h-DgckkWQp9a@y^JU4QnTpRaU27b!BmNuOO?gX4jidOgpFRfDQh+|YoKL&KfFreXqj(IEy40ZtXu47s| z%XPC{RJ5SuAr_T*BrudPt%O^WiGpLgCJRnDa)*S{>9mf=SkkbpV+BuitYTE)awqF~ zW$0K_Y@RCD{&QL+(A!C{zP&38Ebo*mzh84@g`KnOG{jm>GwsYv7T~fBX;j!LzfrA9 zt0*v?Jk{1#mGcv4RPDkUIKq+t#~g6&RuX}M5uWOHiRlG_FJrWw{3F4X*Vz(nKp^!6-Ufov5bq6iH=rvGU(W|bQw{VS9RJEqHV`>D{+ZgM$@jX+Nni>ym?Z}< z6t^MxDZ|9dG gB4Np=x6=*<4T6W5D$LSVEA&=KJGsDh>O8pd2Z}ZK>Hq)$ literal 0 HcmV?d00001 diff --git a/build/tmp/compileJava/source-classes-mapping.txt b/build/tmp/compileJava/source-classes-mapping.txt index a96fe92..2fa410a 100644 --- a/build/tmp/compileJava/source-classes-mapping.txt +++ b/build/tmp/compileJava/source-classes-mapping.txt @@ -1,4 +1,18 @@ -TCPServer.java - TCPServer -TCPClient.java - TCPClient +join/Main.java + join.Main +join/MyThread.java + join.MyThread +semaphore/Main.java + semaphore.Main +semaphore/MyThread.java + semaphore.MyThread +semaphore/Semaphore.java + semaphore.Semaphore +producerConsumer/Consumer.java + producerConsumer.Consumer +producerConsumer/Main.java + producerConsumer.Main +producerConsumer/Queue.java + producerConsumer.Queue +producerConsumer/Producer.java + producerConsumer.Producer diff --git a/src/main/java/TCPClient.java b/src/main/java/TCPClient.java deleted file mode 100644 index c644169..0000000 --- a/src/main/java/TCPClient.java +++ /dev/null @@ -1,38 +0,0 @@ -import java.io.*; -import java.net.*; - -class TCPClient { - public static void main(String argv[]) throws Exception { - String sentence; - String modifiedSentence; - - /* Inizializza l'input stream (da tastiera) */ - BufferedReader inFromUser = - new BufferedReader(new InputStreamReader(System.in)); - - /* Inizializza una socket client, connessa al server */ - Socket clientSocket = new Socket("localhost", 6789); - - /* Inizializza lo stream di output verso la socket */ - DataOutputStream outToServer = - new DataOutputStream(clientSocket.getOutputStream()); - - /* Inizializza lo stream di input dalla socket */ - BufferedReader inFromServer = - new BufferedReader(new - InputStreamReader(clientSocket.getInputStream())); - - /* Legge una linea da tastiera */ - sentence = inFromUser.readLine(); - - /* Invia la linea al server */ - outToServer.writeBytes(sentence + '\n'); - - /* Legge la risposta inviata dal server (linea terminata da \n) */ - modifiedSentence = inFromServer.readLine(); - - System.out.println("FROM SERVER: " + modifiedSentence); - - clientSocket.close(); - } -} diff --git a/src/main/java/TCPServer.java b/src/main/java/TCPServer.java deleted file mode 100644 index 5e565ed..0000000 --- a/src/main/java/TCPServer.java +++ /dev/null @@ -1,43 +0,0 @@ -import java.io.*; -import java.net.*; - -class TCPServer { - - public static void main(String argv[]) throws Exception - { - String clientSentence; - String capitalizedSentence; - - /* Crea una "listening socket" sulla porta specificata */ - ServerSocket welcomeSocket = new ServerSocket(6789); - - while(true) { - /* - * Viene chiamata accept (bloccante). - * All'arrivo di una nuova connessione crea una nuova - * "established socket" - */ - Socket connectionSocket = welcomeSocket.accept(); - - /* Inizializza lo stream di input dalla socket */ - BufferedReader inFromClient = - new BufferedReader(new - InputStreamReader(connectionSocket.getInputStream())); - - /* Inizializza lo stream di output verso la socket */ - DataOutputStream outToClient = - new DataOutputStream(connectionSocket.getOutputStream()); - - /* Legge una linea (terminata da \n) dal client */ - clientSentence = inFromClient.readLine(); - - capitalizedSentence = clientSentence.toUpperCase() + '\n'; - - /* Invia la risposta al client */ - outToClient.writeBytes(capitalizedSentence); - - connectionSocket.close(); - - } - } -} diff --git a/src/main/java/join/Main.java b/src/main/java/join/Main.java new file mode 100644 index 0000000..fedf709 --- /dev/null +++ b/src/main/java/join/Main.java @@ -0,0 +1,33 @@ +package join; + + +import java.util.ArrayList; +import java.util.Random; + +public class Main { + + public static void main(String arg[]) throws Exception { + Random r = new Random(); + ArrayList threads = new ArrayList(); + //create some threads + for (int i=0; i<10; i++) { + MyThread mt = new MyThread(r); + threads.add(mt); + } + System.out.println("All threads have been created."); + //start all the threads + for (Thread t: threads) { + t.start(); + } + System.out.println("All threads have been started."); + System.out.println("Start waiting for all thread to finish..."); + //wait all the thread to finish + for (Thread t : threads) { + t.join(); + } + + System.out.println("...All thread finished!"); + } + +} + diff --git a/src/main/java/join/MyThread.java b/src/main/java/join/MyThread.java new file mode 100644 index 0000000..ac6ed1c --- /dev/null +++ b/src/main/java/join/MyThread.java @@ -0,0 +1,30 @@ +package join; + +import java.util.Random; + +public class MyThread extends Thread { + private Random rnd; + + MyThread(Random r) { + rnd = r; + } + + public void run() { + int seconds = rnd.nextInt(10) + 1; + + System.out.println("A thread started!"); + + try + { + Thread.sleep(seconds * 1000); + } + catch(Exception ex) + { + ex.printStackTrace(); + } + + System.out.println("A thread died!"); + + } + +} diff --git a/src/main/java/producerConsumer/Consumer.java b/src/main/java/producerConsumer/Consumer.java new file mode 100644 index 0000000..9b14fba --- /dev/null +++ b/src/main/java/producerConsumer/Consumer.java @@ -0,0 +1,22 @@ +package producerConsumer; + +public class Consumer implements Runnable { + + private final Queue queue; + private final String id; + + public Consumer(String id, Queue q) { + this.id = id; + queue = q; + } + + public void run() { + while (true) { + consume(queue.take()); + } + } + + public void consume(String message) { + System.out.println("Cons. " + id + ": prelevato " + message); + } +} diff --git a/src/main/java/producerConsumer/Main.java b/src/main/java/producerConsumer/Main.java new file mode 100644 index 0000000..dee4cb9 --- /dev/null +++ b/src/main/java/producerConsumer/Main.java @@ -0,0 +1,17 @@ +package producerConsumer; + +public class Main { + public static void main(String[] args) { + Queue q = new Queue(); + Producer p1 = new Producer("p1", q); + Producer p2 = new Producer("p2", q); + Producer p3 = new Producer("p3", q); + Consumer c1 = new Consumer("c1", q); + Consumer c2 = new Consumer("c2", q); + new Thread(p1).start(); + new Thread(p2).start(); + new Thread(p3).start(); + new Thread(c1).start(); + new Thread(c2).start(); + } +} diff --git a/src/main/java/producerConsumer/Producer.java b/src/main/java/producerConsumer/Producer.java new file mode 100644 index 0000000..628d4b5 --- /dev/null +++ b/src/main/java/producerConsumer/Producer.java @@ -0,0 +1,31 @@ +package producerConsumer; + +public class Producer implements Runnable { + + private final String id; + private final Queue queue; + + public Producer(String id, Queue q) { this.id = id; queue = q; } + + public void run() { + while (true) { + String message = produce(); + System.out.println("Prod. " + id + ": inserisco " + message); + queue.put(message); + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + private int counter = 0; + + public String produce() { + counter++; + return "Messaggio da " + id + " n. " + counter; + } + +} diff --git a/src/main/java/producerConsumer/Queue.java b/src/main/java/producerConsumer/Queue.java new file mode 100644 index 0000000..3ab6093 --- /dev/null +++ b/src/main/java/producerConsumer/Queue.java @@ -0,0 +1,34 @@ +package producerConsumer; + +import java.util.ArrayList; + +public class Queue { + + public ArrayList buffer = new ArrayList(); + + public synchronized void put(String message) { + buffer.add(message); + notify(); + } + + public synchronized String take() { + String message = null; + + while(buffer.size() == 0) { + try { + wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + if(buffer.size()>0){ + message = buffer.get(0); + buffer.remove(0); + } + + + return message; + } + +} diff --git a/src/main/java/semaphore/Main.java b/src/main/java/semaphore/Main.java new file mode 100644 index 0000000..1315fcb --- /dev/null +++ b/src/main/java/semaphore/Main.java @@ -0,0 +1,23 @@ +package semaphore; + +import java.util.ArrayList; +import java.util.Random; + +public class Main { + public static void main(String arg[]) throws Exception { + Random r = new Random(); + ArrayList threads = new ArrayList(); + Semaphore s = new Semaphore(4); + //create some threads + for (int i=0; i<10; i++) { + MyThread mt = new MyThread(r, i, s); + threads.add(mt); + } + + //start all the threads + for (Thread t: threads) { + t.start(); + } + } +} + diff --git a/src/main/java/semaphore/MyThread.java b/src/main/java/semaphore/MyThread.java new file mode 100644 index 0000000..b15b661 --- /dev/null +++ b/src/main/java/semaphore/MyThread.java @@ -0,0 +1,32 @@ +package semaphore; + +import java.util.Random; + +public class MyThread extends Thread { + private Random rnd; + private int id; + private Semaphore sem; + + MyThread(Random r, int i, Semaphore s) { + rnd = r; + id = i; + sem=s; + } + + public void run() { + wasteSomeTime(); //Simulate the thread is doing something else + System.out.println("Thread " + id + " wants to enter in the critical region"); + sem.enter(); + System.out.println("Thread " + id + " entered in the critical region!"); + wasteSomeTime(); //it takes some times to compleate the work in the critical region + System.out.println("Thread " + id + " is going to get out from the critical region"); + sem.exit(); + }//end run + + private void wasteSomeTime() { + int seconds = rnd.nextInt(10) + 1; + try {Thread.sleep(seconds*1000);} + catch(Exception ex) {ex.printStackTrace();} + } +} //end class + diff --git a/src/main/java/semaphore/Semaphore.java b/src/main/java/semaphore/Semaphore.java new file mode 100644 index 0000000..f075e31 --- /dev/null +++ b/src/main/java/semaphore/Semaphore.java @@ -0,0 +1,30 @@ +package semaphore;//Classe che implementa tramite wait e notify un Semaforo. +//Se non vi ricordate cosa sia un semaforo, google is your best friend. + +public class Semaphore { + private int maxNumber; //numero massimo di thread + private int threadsIn; //conteggio dei thread nell'area critica + + Semaphore(int max) { + maxNumber = max; + threadsIn = 0; + } + + public synchronized void enter() { + System.out.println("" + threadsIn + " in the critical region..."); + //quando abbiamo raggiunto il numero massimo di thread, chi vuole entrare aspetta + while (threadsIn >= maxNumber) { + try {this.wait();} + catch(InterruptedException ie) {ie.printStackTrace();} + } + + threadsIn++; + } + + public synchronized void exit() { + threadsIn--; + //quando un thread esce dall'area critica, sveglia qualcuno in attesa di entrare (se presente) + this.notify(); + } +} + -- 2.18.1