From 109a610ee5884e3e1258b0d39efa22b515d3ea3a Mon Sep 17 00:00:00 2001 From: mirimatcode Date: Wed, 6 Apr 2022 22:41:27 +0200 Subject: [PATCH] primo commit --- build.xml | 73 + build/classes/.netbeans_automatic_build | 0 build/classes/.netbeans_update_resources | 0 .../classes/produttoreconsumatore/Cesta.class | Bin 0 -> 1057 bytes .../produttoreconsumatore/Consumatore.class | Bin 0 -> 1299 bytes .../produttoreconsumatore/Produttore.class | Bin 0 -> 1298 bytes .../ProduttoreConsumatore.class | Bin 0 -> 1208 bytes manifest.mf | 3 + nbproject/build-impl.xml | 1413 +++++++++++++++++ nbproject/genfiles.properties | 8 + nbproject/private/private.properties | 2 + nbproject/private/private.xml | 9 + nbproject/project.properties | 73 + nbproject/project.xml | 15 + src/produttoreconsumatore/Cesta.java | 28 + src/produttoreconsumatore/Consumatore.java | 40 + src/produttoreconsumatore/Produttore.java | 40 + .../ProduttoreConsumatore.java | 20 + 18 files changed, 1724 insertions(+) create mode 100644 build.xml create mode 100644 build/classes/.netbeans_automatic_build create mode 100644 build/classes/.netbeans_update_resources create mode 100644 build/classes/produttoreconsumatore/Cesta.class create mode 100644 build/classes/produttoreconsumatore/Consumatore.class create mode 100644 build/classes/produttoreconsumatore/Produttore.class create mode 100644 build/classes/produttoreconsumatore/ProduttoreConsumatore.class create mode 100644 manifest.mf create mode 100644 nbproject/build-impl.xml create mode 100644 nbproject/genfiles.properties create mode 100644 nbproject/private/private.properties create mode 100644 nbproject/private/private.xml create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 src/produttoreconsumatore/Cesta.java create mode 100644 src/produttoreconsumatore/Consumatore.java create mode 100644 src/produttoreconsumatore/Produttore.java create mode 100644 src/produttoreconsumatore/ProduttoreConsumatore.java diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..bd8be9d --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project ProduttoreConsumatore. + + + diff --git a/build/classes/.netbeans_automatic_build b/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/build/classes/.netbeans_update_resources b/build/classes/.netbeans_update_resources new file mode 100644 index 0000000..e69de29 diff --git a/build/classes/produttoreconsumatore/Cesta.class b/build/classes/produttoreconsumatore/Cesta.class new file mode 100644 index 0000000000000000000000000000000000000000..557c1b1784e0efecffcd9f3a304a075a0bc3f6c8 GIT binary patch literal 1057 zcmah{YirX`7=BKhHf@aU>^i5rnR)3Y+Qqx#h94XVgQ9~coAN^&yrKlw$` z4ix+W{wVQHQoGG{laTkk_vd-vbAJ8){u96>Jl9adMiG~BqX+|=DsE~}uu;IR_`I!A zy$oL#lkqkZm-(49c!Q5DewEtMf6GVnn<5BML0FlVr!Y_GutVV+lT@_2v0^ zEW80jtC41$n0mW;#x-386|Ob*E(#ZQQ!#Qa5{Fkx|}Lt1rm@fYLicu9BZXH76)cP@F)U;L^V^B?2g;Mih@>>NA+@=fMn4 v!|4BmsU~yOsPQ})dVw@Uycdhkc$%C^!+atoT}eK1uAC^&%{ZW1m#t*(kL^K8^Dkuu5XwWLGpjJV7A2y?`CcEqGZp!k+#jE}d z&Q=+uJb2fee@K13!OAIm@UZh*=Sra=47S z9Ll&N*3}%YVLrS1VU=Y-ju{I!uIDg-8#Weg+_cc=>L^wgCaR$cYDpXiM!SI@B@HEJ zxgz0Z3;mI9sONzRES#ynR83V*Vy|9is+$<2{kXizgm8y7%pQ(H_0|j4{YV?H!6?h} z?X{;y*FD|jLUzUTz4(rW-Qr)t{{{EI@r%zaWGX>TTNtc*zJ8oEwzb((+jXuStp={D zKU2mN|8OxA?|6}g>29<;{bMhBP2y7)1;*lzhwZB?|3!J-kF_yL80*@DH?9t2FYsA1 zuo)}&)rJaFJYE^G0`p?d*YUPiel)ikB*xWM-PHAaz8}O&3dyL@?nS!ylP0(JYH}U9 zcK$<8PBc{M(3_K+bZ`=r4u)~m!7&sZ92ao{1sk^8e2Y0dR;2!Q< zIGxTy*TXodVA8@=m*MI#A+OF(TRTRp+Mmt44w?m9xvvw?@Kj@65Zcpihnzayt-qjjkMpV~2zI1q=v$So-UfV1hh47J5V HY3qgGWur5i literal 0 HcmV?d00001 diff --git a/build/classes/produttoreconsumatore/Produttore.class b/build/classes/produttoreconsumatore/Produttore.class new file mode 100644 index 0000000000000000000000000000000000000000..f1e10f42401a36e7491766c4850b9bca5167d46d GIT binary patch literal 1298 zcmbtUO;Zy=5PbtlR^k#qMFII14FM7r6a`ceve6sU@P?Q36Pu=qySWFZROa)GH%q_y(G!a5VGJFH=LTTqqnTz|z2ly)nOvMf_y zThprSsu~wk^RDNHj|KL#e{KG+cK;h6+Z0GF`6VULQgl7_GOBDTy&<>CTxl=*jx29V z?Hd1dF%j;#fxz$uu-E=DNh%t3v62g=ev`WU>a&AFVSW0as5k zw{<8N4yAx4oxRA_q@eeFJn^UtG`aEA29C=b4y%%Zp{=T2FN`l{LrX_th>xq4k1WBD zZr%IKt(+XHzAQU>}_PERG)`b8zxK?pNRsrkPy~>KuPO zAU>O@I@qg+-G(rTEM);VnK{Cr*eGUbn^SZV!4z=}GH$TXo}Oozw#C?<#ey4jQVfq$ K3lZ7c-jx literal 0 HcmV?d00001 diff --git a/build/classes/produttoreconsumatore/ProduttoreConsumatore.class b/build/classes/produttoreconsumatore/ProduttoreConsumatore.class new file mode 100644 index 0000000000000000000000000000000000000000..4c3b212a8832384a75c7e9fba7db51ea32a94411 GIT binary patch literal 1208 zcmbtUTTc@~6#k~&?ZUD`DOd#riWg|PEs8e^!3Wf&rd$#T3Gr#z9brkk+sw`qcuuyHt$WN4tr0}9JPU>8f?#`ujqa$6VBy}Ey4Ef^w>IpyP zZjFaW?yizSc(mFA!Q~N!9qOVcXns%^VH`xE*buSe46MS?6N@_k5Xp$4&<>iYpym=9 zFOgD&%H1V{#xcPn0E2OZe+r^X7z?SRDRS#?%XXxw1>%$hrq>QXeob|)>=ev?^U)Ix zMSx-pPl?}+66uMzfo|Jq*B&hDvK-1EI@_7%_Th=})Sv2F1FnQhNSQR0@Gm*%* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..29699e5 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=201797c6 +build.xml.script.CRC32=d55de831 +build.xml.stylesheet.CRC32=8064a381@1.75.2.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=201797c6 +nbproject/build-impl.xml.script.CRC32=25c87c97 +nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..26ce0ca --- /dev/null +++ b/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=/home/nfutu/.netbeans/8.0.2/build.properties diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml new file mode 100644 index 0000000..25c6f6a --- /dev/null +++ b/nbproject/private/private.xml @@ -0,0 +1,9 @@ + + + + + + file:/home/nfutu/Extra/Dropbox/Progetto%20PAS/ProduttoreConsumatore/src/produttoreconsumatore/ProduttoreConsumatore.java + + + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..56f1e79 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,73 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/ProduttoreConsumatore.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=produttoreconsumatore.ProduttoreConsumatore +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..151f124 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + ProduttoreConsumatore + + + + + + + + + diff --git a/src/produttoreconsumatore/Cesta.java b/src/produttoreconsumatore/Cesta.java new file mode 100644 index 0000000..916cc5d --- /dev/null +++ b/src/produttoreconsumatore/Cesta.java @@ -0,0 +1,28 @@ +package produttoreconsumatore; + +public class Cesta +{ + int numeroPanini; + + public Cesta() + { + this.numeroPanini = 0; + } + + public void inserisci() + { + numeroPanini++; + System.out.println("Panino inserito - Panini nella cesta: " + getPanini()); + } + + public void preleva() + { + numeroPanini--; + System.out.println("Panino prelevato - Panini nella cesta: " + getPanini()); + } + + public int getPanini() + { + return numeroPanini; + } +} \ No newline at end of file diff --git a/src/produttoreconsumatore/Consumatore.java b/src/produttoreconsumatore/Consumatore.java new file mode 100644 index 0000000..7c4ba91 --- /dev/null +++ b/src/produttoreconsumatore/Consumatore.java @@ -0,0 +1,40 @@ +package produttoreconsumatore; + +import java.util.concurrent.Semaphore; + +public class Consumatore extends Thread +{ + Cesta cesta; + Semaphore semaforo; + Semaphore spazioInserimento; + Semaphore spazioPrelievo; + + public Consumatore(Cesta cesta, Semaphore semaforo, Semaphore spazioInserimento, Semaphore spazioPrelievo) + { + this.cesta = cesta; + this.semaforo = semaforo; + this.spazioInserimento = spazioInserimento; + this.spazioPrelievo = spazioPrelievo; + } + + @Override + public void run() + { + while(true) + try + { + spazioPrelievo.acquire(); + semaforo.acquire(); + cesta.preleva(); + semaforo.release(); + spazioInserimento.release(); + + //Consuma il panino + sleep((int)(Math.random()*1000)); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } +} diff --git a/src/produttoreconsumatore/Produttore.java b/src/produttoreconsumatore/Produttore.java new file mode 100644 index 0000000..98b4ef2 --- /dev/null +++ b/src/produttoreconsumatore/Produttore.java @@ -0,0 +1,40 @@ +package produttoreconsumatore; + +import java.util.concurrent.Semaphore; + +public class Produttore extends Thread +{ + Cesta cesta; + Semaphore semaforo; + Semaphore spazioInserimento; + Semaphore spazioPrelievo; + + public Produttore(Cesta cesta, Semaphore semaforo, Semaphore spazioInserimento, Semaphore spazioPrelievo) + { + this.cesta = cesta; + this.semaforo = semaforo; + this.spazioInserimento = spazioInserimento; + this.spazioPrelievo = spazioPrelievo; + } + + @Override + public void run() + { + while(true) + try + { + //Produce il panino + sleep((int)(Math.random()*1000)); + + spazioInserimento.acquire(); + semaforo.acquire(); + cesta.inserisci(); + semaforo.release(); + spazioPrelievo.release(); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } +} diff --git a/src/produttoreconsumatore/ProduttoreConsumatore.java b/src/produttoreconsumatore/ProduttoreConsumatore.java new file mode 100644 index 0000000..9c5aa57 --- /dev/null +++ b/src/produttoreconsumatore/ProduttoreConsumatore.java @@ -0,0 +1,20 @@ +package produttoreconsumatore; + +import java.util.concurrent.Semaphore; + +public class ProduttoreConsumatore +{ + public static void main(String[] args) throws InterruptedException + { + int dimensioneCesta = 100; + Semaphore semaforo = new Semaphore(1); + Semaphore spazioInserimento = new Semaphore(100); + Semaphore spazioPrelievo = new Semaphore(0); + + Cesta cesta = new Cesta(); + + new Produttore(cesta, semaforo, spazioInserimento, spazioPrelievo).start(); + Thread.sleep(10000); + new Consumatore(cesta, semaforo, spazioInserimento, spazioPrelievo).start(); + } +}