SlideShare a Scribd company logo
Question I
You are going to use the semaphores for process
synchronization. Therefore, you are asked to develop a
consumer and producer multithreaded program.
Let us assume, that we have a thread (producer, we will call it
producer_thread) reading data (positive integer numbers) from
the keyboard, entered by a user to be stored in an array
(dynamic array). (Assume that the array can hold all numbers
entered without overflow.)
Another thread (consumer, we will call it consumer_thread)
should read data from the array and write them into a file. This
thread should run concurrently with the producer
(producer_thread).
Your program should make sure that the consumer_thread can
read from the array only after the producer_thread has stored
new data. Both threads will stop when the user enters a negative
number (well synchronized).
Another thread (testing_thread) should start reading the array
data as well as the file data and display them on the screen in
order to verify if the consumer and producer have worked in a
correctly synchronized fashion. This thread should not be
synchronized with other threads, it is intended for testing that
consumer thread is synchronized with produce thread.
Provide your tutor with the source code as well as screen
snapshots that show the work of the testing_thread.
1
TM298_TMA_Q2/build.xml
Builds, tests, and runs the project TM298_TMA_Q2.
TM298_TMA_Q2/manifest.mf
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
TM298_TMA_Q2/nbproject/build-impl.xml
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
TM298_TMA_Q2/nbproject/genfiles.properties
build.xml.data.CRC32=f05f63ba
build.xml.script.CRC32=4dc8f402
[email protected]
# 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=f05f63ba
nbproject/build-impl.xml.script.CRC32=6ecbbebf
nbproject/[email protected]
TM298_TMA_Q2/nbproject/private/private.properties
compile.on.save=true
user.properties.file=/Users/macbook/Library/Application
Support/NetBeans/8.2/build.properties
TM298_TMA_Q2/nbproject/project.properties
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}/TM298_TMA_Q2.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.external.vm=true
javac.processorpath=
${javac.classpath}
javac.source=1.8
javac.target=1.8
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=tm298_tma_q2.TM298_TMA_Q2
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
TM298_TMA_Q2/nbproject/project.xml
org.netbeans.modules.java.j2seproject
TM298_TMA_Q2
TM298_TMA_Q2/src/tm298_tma_q2/ArrayStorage.javaTM298_
TMA_Q2/src/tm298_tma_q2/ArrayStorage.java/*
* To change this license header, choose License Headers in Pro
ject Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tm298_tma_q2;
/**
*
* @author macbook
*/
publicclassArrayStorage{
privateInteger[] arrayInt;
privateint size;
privateint item_Counter;// number of items still not taken from i
n the array
privateint index_in;// array index for the writer
privateint index_out;// array index for teh reader
publicArrayStorage(Integer[] arrayInt){
this.arrayInt = arrayInt;
this.size = arrayInt.length;
this.item_Counter =0;
this.index_in =0;
this.index_out =0;
}
publicvoid put_item(int data){
if(this.item_Counter < size){
arrayInt[index_in]= data;
this.item_Counter++;
index_in =(index_in +1)% size;// circular buffer
}
}
publicint take_item(){
int data =0;
if(this.item_Counter !=0){
data = arrayInt[index_out];
this.item_Counter--;//
index_out =(index_out +1)% size;// circular buffer
}
return data;
}
/**
* Get the value of index_out
*
* @return the value of index_out
*/
publicint getIndex_out(){
return index_out;
}
/**
* Set the value of index_out
*
* @param index_out new value of index_out
*/
publicvoid setIndex_out(int index_out){
this.index_out = index_out;
}
/**
* Get the value of index_in
*
* @return the value of index_in
*/
publicint getIndex_in(){
return index_in;
}
/**
* Set the value of index_in
*
* @param index_in new value of index_in
*/
publicvoid setIndex_in(int index_in){
this.index_in = index_in;
}
/**
* Get the value of item_Counter
*
* @return the value of item_Counter
*/
publicint getItem_Counter(){
return item_Counter;
}
/**
* Set the value of item_Counter
*
* @param item_Counter new value of item_Counter
*/
publicvoid setItem_Counter(int item_Counter){
this.item_Counter = item_Counter;
}
/**
* Get the value of size
*
* @return the value of size
*/
publicint getSize(){
return size;
}
/**
* Set the value of size
*
* @param size new value of size
*/
publicvoid setSize(int size){
this.size = size;
}
}
TM298_TMA_Q2/src/tm298_tma_q2/Consumer.javaTM298_TM
A_Q2/src/tm298_tma_q2/Consumer.java/*
* To change this license header, choose License Headers in Pro
ject Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tm298_tma_q2;
/**
*
* @author macbook
*/
publicclassConsumerextendsThread{
privateArrayStorage arrayData;
privateString fileName;
/**
* Get the value of arrayData
*
* @return the value of arrayData
*/
publicConsumer(ArrayStorage arrayData,String fileName){
super();
this.arrayData = arrayData;
}
@Override
publicvoid run(){
super.run();//To change body of generated methods, choose Too
ls | Templates.
// read the data from the arry and save them to file
// stops when negative number is read
}
publicConsumer(String name){
super(name);
}
}
TM298_TMA_Q2/src/tm298_tma_q2/Producer.javaTM298_TM
A_Q2/src/tm298_tma_q2/Producer.java/*
* To change this license header, choose License Headers in Pro
ject Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tm298_tma_q2;
/**
*
* @author macbook
*/
publicclassProducerextendsThread{
privateArrayStorage test;
privateString fileName;
publicProducer(ArrayStorage test,String fileName){
this.test = test;
this.fileName=fileName;
}
@Override
publicvoid run(){
super.run();//To change body of generated methods, choose Too
ls | Templates.
//ask the user to enter Integers, stop when a negative number is
enetred
//put the integer in teh array
// save it in a file to be compared with reader data
}
}
TM298_TMA_Q2/src/tm298_tma_q2/Testing_Thread.javaTM29
8_TMA_Q2/src/tm298_tma_q2/Testing_Thread.java/*
* To change this license header, choose License Headers in Pro
ject Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tm298_tma_q2;
/**
*
* @author macbook
*/
publicclassTesting_ThreadextendsThread{
String readerFileName="reader.txt";
String writerFileName="writer.txt";
publicTesting_Thread(String readerFileName,String writerFileN
ame){
this.readerFileName=readerFileName;
this.writerFileName=writerFileName;
}
@Override
publicvoid run(){
super.run();//To change body of generated methods, choose Too
ls | Templates.
//open read and writer files
//read the data from the reader file and compare them to the con
etent of writer file
// repeat this until the end of the file
// if all data macthes, then you can tell that both threads cosnum
er and producers are well synchronized
}
}
TM298_TMA_Q2/src/tm298_tma_q2/TM298_TMA_Q2.javaTM
298_TMA_Q2/src/tm298_tma_q2/TM298_TMA_Q2.java/*
* To change this license header, choose License Headers in Pro
ject Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tm298_tma_q2;
/**
*
* @author macbook
*/
publicclass TM298_TMA_Q2 {
/**
* @param args the command line arguments
*/
publicstaticvoid main(String[] args){
// TODO code application logic here
String readerFileName="reader.txt";
String writerFileName="writer.txt";
Integer[] arrayInt=newInteger[20];
Thread mainThread=Thread.currentThread();
ArrayStorage shared_buffer=newArrayStorage(arrayInt);
Consumer consumer=newConsumer(shared_buffer, readerFileNa
me);
Producer producer=newProducer(shared_buffer,writerFileName)
;
Testing_Thread test_sync=newTesting_Thread(readerFileName,
writerFileName);
consumer.start();
producer.start();
try{
consumer.join();// wait until the consumer finishes reading
data form the shared buffer
}
catch(Exception e){
System.out.println(e);
}
test_sync.start();
System.out.print("Mission accomplished");
}
}

More Related Content

Similar to Question IYou are going to use the semaphores for process sy.docx

CommissionCalculationbuildclasses.netbeans_automatic_build.docx
CommissionCalculationbuildclasses.netbeans_automatic_build.docxCommissionCalculationbuildclasses.netbeans_automatic_build.docx
CommissionCalculationbuildclasses.netbeans_automatic_build.docx
monicafrancis71118
 
GuiReflectAppbuild.xml Builds, tests, and runs the pro.docx
GuiReflectAppbuild.xml      Builds, tests, and runs the pro.docxGuiReflectAppbuild.xml      Builds, tests, and runs the pro.docx
GuiReflectAppbuild.xml Builds, tests, and runs the pro.docx
shericehewat
 
Ordering System IP2buildclasses.netbeans_automatic_buildO.docx
Ordering System IP2buildclasses.netbeans_automatic_buildO.docxOrdering System IP2buildclasses.netbeans_automatic_buildO.docx
Ordering System IP2buildclasses.netbeans_automatic_buildO.docx
hopeaustin33688
 
MyTunesbuild.xml Builds, tests, and runs the project M.docx
MyTunesbuild.xml      Builds, tests, and runs the project M.docxMyTunesbuild.xml      Builds, tests, and runs the project M.docx
MyTunesbuild.xml Builds, tests, and runs the project M.docx
gilpinleeanna
 
Dost.jar and fo.jar
Dost.jar and fo.jarDost.jar and fo.jar
Dost.jar and fo.jar
Suite Solutions
 
Readme
ReadmeReadme
Readme
rec2006
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnit
Greg.Helton
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
Ankur Dongre
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
Ankur Dongre
 
HW_6-1build.xml Builds, tests, and runs the project HW.docx
HW_6-1build.xml      Builds, tests, and runs the project HW.docxHW_6-1build.xml      Builds, tests, and runs the project HW.docx
HW_6-1build.xml Builds, tests, and runs the project HW.docx
adampcarr67227
 
Testing the frontend
Testing the frontendTesting the frontend
Testing the frontend
Heiko Hardt
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular Framework
RapidValue
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java Developers
Yakov Fain
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
Clinton Dreisbach
 
FileWrite.javaFileWrite.java  To change this license header.docx
FileWrite.javaFileWrite.java  To change this license header.docxFileWrite.javaFileWrite.java  To change this license header.docx
FileWrite.javaFileWrite.java  To change this license header.docx
ssuser454af01
 
AdaCore Paris Tech Day 2016: Eric Perlade - Verification Solutions
AdaCore Paris Tech Day 2016: Eric Perlade - Verification SolutionsAdaCore Paris Tech Day 2016: Eric Perlade - Verification Solutions
AdaCore Paris Tech Day 2016: Eric Perlade - Verification Solutions
jamieayre
 
Maze
MazeMaze
Maze
yito24
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
curwenmichaela
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
hartrobert670
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
ciklum_ods
 

Similar to Question IYou are going to use the semaphores for process sy.docx (20)

CommissionCalculationbuildclasses.netbeans_automatic_build.docx
CommissionCalculationbuildclasses.netbeans_automatic_build.docxCommissionCalculationbuildclasses.netbeans_automatic_build.docx
CommissionCalculationbuildclasses.netbeans_automatic_build.docx
 
GuiReflectAppbuild.xml Builds, tests, and runs the pro.docx
GuiReflectAppbuild.xml      Builds, tests, and runs the pro.docxGuiReflectAppbuild.xml      Builds, tests, and runs the pro.docx
GuiReflectAppbuild.xml Builds, tests, and runs the pro.docx
 
Ordering System IP2buildclasses.netbeans_automatic_buildO.docx
Ordering System IP2buildclasses.netbeans_automatic_buildO.docxOrdering System IP2buildclasses.netbeans_automatic_buildO.docx
Ordering System IP2buildclasses.netbeans_automatic_buildO.docx
 
MyTunesbuild.xml Builds, tests, and runs the project M.docx
MyTunesbuild.xml      Builds, tests, and runs the project M.docxMyTunesbuild.xml      Builds, tests, and runs the project M.docx
MyTunesbuild.xml Builds, tests, and runs the project M.docx
 
Dost.jar and fo.jar
Dost.jar and fo.jarDost.jar and fo.jar
Dost.jar and fo.jar
 
Readme
ReadmeReadme
Readme
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnit
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
HW_6-1build.xml Builds, tests, and runs the project HW.docx
HW_6-1build.xml      Builds, tests, and runs the project HW.docxHW_6-1build.xml      Builds, tests, and runs the project HW.docx
HW_6-1build.xml Builds, tests, and runs the project HW.docx
 
Testing the frontend
Testing the frontendTesting the frontend
Testing the frontend
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular Framework
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java Developers
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
FileWrite.javaFileWrite.java  To change this license header.docx
FileWrite.javaFileWrite.java  To change this license header.docxFileWrite.javaFileWrite.java  To change this license header.docx
FileWrite.javaFileWrite.java  To change this license header.docx
 
AdaCore Paris Tech Day 2016: Eric Perlade - Verification Solutions
AdaCore Paris Tech Day 2016: Eric Perlade - Verification SolutionsAdaCore Paris Tech Day 2016: Eric Perlade - Verification Solutions
AdaCore Paris Tech Day 2016: Eric Perlade - Verification Solutions
 
Maze
MazeMaze
Maze
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 

More from audeleypearl

Mr. Bush, a 45-year-old middle school teacher arrives at the emergen.docx
Mr. Bush, a 45-year-old middle school teacher arrives at the emergen.docxMr. Bush, a 45-year-old middle school teacher arrives at the emergen.docx
Mr. Bush, a 45-year-old middle school teacher arrives at the emergen.docx
audeleypearl
 
Movie Project Presentation Movie TroyInclude Architecture i.docx
Movie Project Presentation Movie TroyInclude Architecture i.docxMovie Project Presentation Movie TroyInclude Architecture i.docx
Movie Project Presentation Movie TroyInclude Architecture i.docx
audeleypearl
 
Motivation and Retention Discuss the specific strategies you pl.docx
Motivation and Retention Discuss the specific strategies you pl.docxMotivation and Retention Discuss the specific strategies you pl.docx
Motivation and Retention Discuss the specific strategies you pl.docx
audeleypearl
 
Mother of the Year In recognition of superlative paren.docx
Mother of the Year         In recognition of superlative paren.docxMother of the Year         In recognition of superlative paren.docx
Mother of the Year In recognition of superlative paren.docx
audeleypearl
 
Mrs. G, a 55 year old Hispanic female, presents to the office for he.docx
Mrs. G, a 55 year old Hispanic female, presents to the office for he.docxMrs. G, a 55 year old Hispanic female, presents to the office for he.docx
Mrs. G, a 55 year old Hispanic female, presents to the office for he.docx
audeleypearl
 
Mr. Rivera is a 72-year-old patient with end stage COPD who is in th.docx
Mr. Rivera is a 72-year-old patient with end stage COPD who is in th.docxMr. Rivera is a 72-year-old patient with end stage COPD who is in th.docx
Mr. Rivera is a 72-year-old patient with end stage COPD who is in th.docx
audeleypearl
 
Mr. B, a 40-year-old avid long-distance runner previously in goo.docx
Mr. B, a 40-year-old avid long-distance runner previously in goo.docxMr. B, a 40-year-old avid long-distance runner previously in goo.docx
Mr. B, a 40-year-old avid long-distance runner previously in goo.docx
audeleypearl
 
Moving members of the organization through the change process ca.docx
Moving members of the organization through the change process ca.docxMoving members of the organization through the change process ca.docx
Moving members of the organization through the change process ca.docx
audeleypearl
 
Mr. Friend is acrime analystwith the SantaCruz, Califo.docx
Mr. Friend is acrime analystwith the SantaCruz, Califo.docxMr. Friend is acrime analystwith the SantaCruz, Califo.docx
Mr. Friend is acrime analystwith the SantaCruz, Califo.docx
audeleypearl
 
Mr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docx
Mr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docxMr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docx
Mr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docx
audeleypearl
 
Motor Milestones occur in a predictable developmental progression in.docx
Motor Milestones occur in a predictable developmental progression in.docxMotor Milestones occur in a predictable developmental progression in.docx
Motor Milestones occur in a predictable developmental progression in.docx
audeleypearl
 
Most women experience their closest friendships with those of th.docx
Most women experience their closest friendships with those of th.docxMost women experience their closest friendships with those of th.docx
Most women experience their closest friendships with those of th.docx
audeleypearl
 
Most patients with mental health disorders are not aggressive. Howev.docx
Most patients with mental health disorders are not aggressive. Howev.docxMost patients with mental health disorders are not aggressive. Howev.docx
Most patients with mental health disorders are not aggressive. Howev.docx
audeleypearl
 
Most of our class readings and discussions to date have dealt wi.docx
Most of our class readings and discussions to date have dealt wi.docxMost of our class readings and discussions to date have dealt wi.docx
Most of our class readings and discussions to date have dealt wi.docx
audeleypearl
 
Most people agree we live in stressful times. Does stress and re.docx
Most people agree we live in stressful times. Does stress and re.docxMost people agree we live in stressful times. Does stress and re.docx
Most people agree we live in stressful times. Does stress and re.docx
audeleypearl
 
Most of the ethical prescriptions of normative moral philosophy .docx
Most of the ethical prescriptions of normative moral philosophy .docxMost of the ethical prescriptions of normative moral philosophy .docx
Most of the ethical prescriptions of normative moral philosophy .docx
audeleypearl
 
Most healthcare organizations in the country are implementing qualit.docx
Most healthcare organizations in the country are implementing qualit.docxMost healthcare organizations in the country are implementing qualit.docx
Most healthcare organizations in the country are implementing qualit.docx
audeleypearl
 
More work is necessary on how to efficiently model uncertainty in ML.docx
More work is necessary on how to efficiently model uncertainty in ML.docxMore work is necessary on how to efficiently model uncertainty in ML.docx
More work is necessary on how to efficiently model uncertainty in ML.docx
audeleypearl
 
Mortgage-Backed Securities and the Financial CrisisKelly Finn.docx
Mortgage-Backed Securities and the Financial CrisisKelly Finn.docxMortgage-Backed Securities and the Financial CrisisKelly Finn.docx
Mortgage-Backed Securities and the Financial CrisisKelly Finn.docx
audeleypearl
 
Moral Development  Lawrence Kohlberg developed six stages to mora.docx
Moral Development  Lawrence Kohlberg developed six stages to mora.docxMoral Development  Lawrence Kohlberg developed six stages to mora.docx
Moral Development  Lawrence Kohlberg developed six stages to mora.docx
audeleypearl
 

More from audeleypearl (20)

Mr. Bush, a 45-year-old middle school teacher arrives at the emergen.docx
Mr. Bush, a 45-year-old middle school teacher arrives at the emergen.docxMr. Bush, a 45-year-old middle school teacher arrives at the emergen.docx
Mr. Bush, a 45-year-old middle school teacher arrives at the emergen.docx
 
Movie Project Presentation Movie TroyInclude Architecture i.docx
Movie Project Presentation Movie TroyInclude Architecture i.docxMovie Project Presentation Movie TroyInclude Architecture i.docx
Movie Project Presentation Movie TroyInclude Architecture i.docx
 
Motivation and Retention Discuss the specific strategies you pl.docx
Motivation and Retention Discuss the specific strategies you pl.docxMotivation and Retention Discuss the specific strategies you pl.docx
Motivation and Retention Discuss the specific strategies you pl.docx
 
Mother of the Year In recognition of superlative paren.docx
Mother of the Year         In recognition of superlative paren.docxMother of the Year         In recognition of superlative paren.docx
Mother of the Year In recognition of superlative paren.docx
 
Mrs. G, a 55 year old Hispanic female, presents to the office for he.docx
Mrs. G, a 55 year old Hispanic female, presents to the office for he.docxMrs. G, a 55 year old Hispanic female, presents to the office for he.docx
Mrs. G, a 55 year old Hispanic female, presents to the office for he.docx
 
Mr. Rivera is a 72-year-old patient with end stage COPD who is in th.docx
Mr. Rivera is a 72-year-old patient with end stage COPD who is in th.docxMr. Rivera is a 72-year-old patient with end stage COPD who is in th.docx
Mr. Rivera is a 72-year-old patient with end stage COPD who is in th.docx
 
Mr. B, a 40-year-old avid long-distance runner previously in goo.docx
Mr. B, a 40-year-old avid long-distance runner previously in goo.docxMr. B, a 40-year-old avid long-distance runner previously in goo.docx
Mr. B, a 40-year-old avid long-distance runner previously in goo.docx
 
Moving members of the organization through the change process ca.docx
Moving members of the organization through the change process ca.docxMoving members of the organization through the change process ca.docx
Moving members of the organization through the change process ca.docx
 
Mr. Friend is acrime analystwith the SantaCruz, Califo.docx
Mr. Friend is acrime analystwith the SantaCruz, Califo.docxMr. Friend is acrime analystwith the SantaCruz, Califo.docx
Mr. Friend is acrime analystwith the SantaCruz, Califo.docx
 
Mr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docx
Mr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docxMr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docx
Mr. E is a pleasant, 70-year-old, black, maleSource Self, rel.docx
 
Motor Milestones occur in a predictable developmental progression in.docx
Motor Milestones occur in a predictable developmental progression in.docxMotor Milestones occur in a predictable developmental progression in.docx
Motor Milestones occur in a predictable developmental progression in.docx
 
Most women experience their closest friendships with those of th.docx
Most women experience their closest friendships with those of th.docxMost women experience their closest friendships with those of th.docx
Most women experience their closest friendships with those of th.docx
 
Most patients with mental health disorders are not aggressive. Howev.docx
Most patients with mental health disorders are not aggressive. Howev.docxMost patients with mental health disorders are not aggressive. Howev.docx
Most patients with mental health disorders are not aggressive. Howev.docx
 
Most of our class readings and discussions to date have dealt wi.docx
Most of our class readings and discussions to date have dealt wi.docxMost of our class readings and discussions to date have dealt wi.docx
Most of our class readings and discussions to date have dealt wi.docx
 
Most people agree we live in stressful times. Does stress and re.docx
Most people agree we live in stressful times. Does stress and re.docxMost people agree we live in stressful times. Does stress and re.docx
Most people agree we live in stressful times. Does stress and re.docx
 
Most of the ethical prescriptions of normative moral philosophy .docx
Most of the ethical prescriptions of normative moral philosophy .docxMost of the ethical prescriptions of normative moral philosophy .docx
Most of the ethical prescriptions of normative moral philosophy .docx
 
Most healthcare organizations in the country are implementing qualit.docx
Most healthcare organizations in the country are implementing qualit.docxMost healthcare organizations in the country are implementing qualit.docx
Most healthcare organizations in the country are implementing qualit.docx
 
More work is necessary on how to efficiently model uncertainty in ML.docx
More work is necessary on how to efficiently model uncertainty in ML.docxMore work is necessary on how to efficiently model uncertainty in ML.docx
More work is necessary on how to efficiently model uncertainty in ML.docx
 
Mortgage-Backed Securities and the Financial CrisisKelly Finn.docx
Mortgage-Backed Securities and the Financial CrisisKelly Finn.docxMortgage-Backed Securities and the Financial CrisisKelly Finn.docx
Mortgage-Backed Securities and the Financial CrisisKelly Finn.docx
 
Moral Development  Lawrence Kohlberg developed six stages to mora.docx
Moral Development  Lawrence Kohlberg developed six stages to mora.docxMoral Development  Lawrence Kohlberg developed six stages to mora.docx
Moral Development  Lawrence Kohlberg developed six stages to mora.docx
 

Recently uploaded

Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDFLifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Vivekanand Anglo Vedic Academy
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
JomonJoseph58
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 

Recently uploaded (20)

Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDFLifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 

Question IYou are going to use the semaphores for process sy.docx

  • 1. Question I You are going to use the semaphores for process synchronization. Therefore, you are asked to develop a consumer and producer multithreaded program. Let us assume, that we have a thread (producer, we will call it producer_thread) reading data (positive integer numbers) from the keyboard, entered by a user to be stored in an array (dynamic array). (Assume that the array can hold all numbers entered without overflow.) Another thread (consumer, we will call it consumer_thread) should read data from the array and write them into a file. This thread should run concurrently with the producer (producer_thread). Your program should make sure that the consumer_thread can read from the array only after the producer_thread has stored new data. Both threads will stop when the user enters a negative number (well synchronized). Another thread (testing_thread) should start reading the array data as well as the file data and display them on the screen in order to verify if the consumer and producer have worked in a correctly synchronized fashion. This thread should not be synchronized with other threads, it is intended for testing that consumer thread is synchronized with produce thread. Provide your tutor with the source code as well as screen snapshots that show the work of the testing_thread.
  • 2. 1 TM298_TMA_Q2/build.xml Builds, tests, and runs the project TM298_TMA_Q2. TM298_TMA_Q2/manifest.mf Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build TM298_TMA_Q2/nbproject/build-impl.xml
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. 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
  • 9.
  • 10.
  • 12.
  • 13.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21. Must set JVM to use for profiling in profiler.info.jvm Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28. Must select some files in the IDE or set javac.includes
  • 29. To run this application from the command line without Ant, try: java -jar "${dist.jar.resolved}"
  • 30. Must select one file in the IDE or set run.class Must select one file in the IDE or set run.class
  • 31. 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.
  • 32. 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.
  • 33. Must select one file in the IDE or set run.class
  • 34. 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
  • 35.
  • 36. Must select some files in the IDE or set javac.includes Some tests failed; see details above.
  • 37. 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
  • 38. Must select one file in the IDE or set applet.url Must select one file in the IDE or set applet.url
  • 40. [email protected] # 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=f05f63ba nbproject/build-impl.xml.script.CRC32=6ecbbebf nbproject/[email protected] TM298_TMA_Q2/nbproject/private/private.properties compile.on.save=true user.properties.file=/Users/macbook/Library/Application Support/NetBeans/8.2/build.properties TM298_TMA_Q2/nbproject/project.properties 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
  • 41. 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}/TM298_TMA_Q2.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.external.vm=true javac.processorpath= ${javac.classpath} javac.source=1.8 javac.target=1.8 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
  • 42. javadoc.use=true javadoc.version=false javadoc.windowtitle= main.class=tm298_tma_q2.TM298_TMA_Q2 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 TM298_TMA_Q2/nbproject/project.xml org.netbeans.modules.java.j2seproject TM298_TMA_Q2
  • 43. TM298_TMA_Q2/src/tm298_tma_q2/ArrayStorage.javaTM298_ TMA_Q2/src/tm298_tma_q2/ArrayStorage.java/* * To change this license header, choose License Headers in Pro ject Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package tm298_tma_q2; /** * * @author macbook */ publicclassArrayStorage{ privateInteger[] arrayInt; privateint size; privateint item_Counter;// number of items still not taken from i n the array privateint index_in;// array index for the writer privateint index_out;// array index for teh reader publicArrayStorage(Integer[] arrayInt){ this.arrayInt = arrayInt; this.size = arrayInt.length; this.item_Counter =0;
  • 44. this.index_in =0; this.index_out =0; } publicvoid put_item(int data){ if(this.item_Counter < size){ arrayInt[index_in]= data; this.item_Counter++; index_in =(index_in +1)% size;// circular buffer } } publicint take_item(){ int data =0; if(this.item_Counter !=0){ data = arrayInt[index_out]; this.item_Counter--;// index_out =(index_out +1)% size;// circular buffer } return data; } /** * Get the value of index_out * * @return the value of index_out */ publicint getIndex_out(){ return index_out; } /** * Set the value of index_out * * @param index_out new value of index_out
  • 45. */ publicvoid setIndex_out(int index_out){ this.index_out = index_out; } /** * Get the value of index_in * * @return the value of index_in */ publicint getIndex_in(){ return index_in; } /** * Set the value of index_in * * @param index_in new value of index_in */ publicvoid setIndex_in(int index_in){ this.index_in = index_in; } /** * Get the value of item_Counter * * @return the value of item_Counter */ publicint getItem_Counter(){ return item_Counter; } /** * Set the value of item_Counter * * @param item_Counter new value of item_Counter
  • 46. */ publicvoid setItem_Counter(int item_Counter){ this.item_Counter = item_Counter; } /** * Get the value of size * * @return the value of size */ publicint getSize(){ return size; } /** * Set the value of size * * @param size new value of size */ publicvoid setSize(int size){ this.size = size; } } TM298_TMA_Q2/src/tm298_tma_q2/Consumer.javaTM298_TM A_Q2/src/tm298_tma_q2/Consumer.java/* * To change this license header, choose License Headers in Pro ject Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package tm298_tma_q2; /**
  • 47. * * @author macbook */ publicclassConsumerextendsThread{ privateArrayStorage arrayData; privateString fileName; /** * Get the value of arrayData * * @return the value of arrayData */ publicConsumer(ArrayStorage arrayData,String fileName){ super(); this.arrayData = arrayData; } @Override publicvoid run(){ super.run();//To change body of generated methods, choose Too ls | Templates. // read the data from the arry and save them to file // stops when negative number is read } publicConsumer(String name){ super(name); }
  • 48. } TM298_TMA_Q2/src/tm298_tma_q2/Producer.javaTM298_TM A_Q2/src/tm298_tma_q2/Producer.java/* * To change this license header, choose License Headers in Pro ject Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package tm298_tma_q2; /** * * @author macbook */ publicclassProducerextendsThread{ privateArrayStorage test; privateString fileName; publicProducer(ArrayStorage test,String fileName){ this.test = test; this.fileName=fileName; } @Override publicvoid run(){ super.run();//To change body of generated methods, choose Too ls | Templates. //ask the user to enter Integers, stop when a negative number is enetred //put the integer in teh array // save it in a file to be compared with reader data
  • 49. } } TM298_TMA_Q2/src/tm298_tma_q2/Testing_Thread.javaTM29 8_TMA_Q2/src/tm298_tma_q2/Testing_Thread.java/* * To change this license header, choose License Headers in Pro ject Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package tm298_tma_q2; /** * * @author macbook */ publicclassTesting_ThreadextendsThread{ String readerFileName="reader.txt"; String writerFileName="writer.txt"; publicTesting_Thread(String readerFileName,String writerFileN ame){ this.readerFileName=readerFileName; this.writerFileName=writerFileName; } @Override publicvoid run(){ super.run();//To change body of generated methods, choose Too ls | Templates.
  • 50. //open read and writer files //read the data from the reader file and compare them to the con etent of writer file // repeat this until the end of the file // if all data macthes, then you can tell that both threads cosnum er and producers are well synchronized } } TM298_TMA_Q2/src/tm298_tma_q2/TM298_TMA_Q2.javaTM 298_TMA_Q2/src/tm298_tma_q2/TM298_TMA_Q2.java/* * To change this license header, choose License Headers in Pro ject Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package tm298_tma_q2; /** * * @author macbook */ publicclass TM298_TMA_Q2 { /** * @param args the command line arguments */ publicstaticvoid main(String[] args){ // TODO code application logic here String readerFileName="reader.txt";
  • 51. String writerFileName="writer.txt"; Integer[] arrayInt=newInteger[20]; Thread mainThread=Thread.currentThread(); ArrayStorage shared_buffer=newArrayStorage(arrayInt); Consumer consumer=newConsumer(shared_buffer, readerFileNa me); Producer producer=newProducer(shared_buffer,writerFileName) ; Testing_Thread test_sync=newTesting_Thread(readerFileName, writerFileName); consumer.start(); producer.start(); try{ consumer.join();// wait until the consumer finishes reading data form the shared buffer } catch(Exception e){ System.out.println(e); } test_sync.start(); System.out.print("Mission accomplished"); } }