16. Work Breakdown Structure - Text Alternative
Return to parent-slide containing images.
Level 1 consists of the E-Slim Tablet x-13 Prototype.
Level 2 consists of Hardware, CPU, and More Items.
Level 3 consists of the Power Supply, Flash ROM, and I/O
Controller, all flowing from the CPU in Level 2.
Level 4 consists of the Battery and Charger (flowing from the
Power Supply in Level 3) and the USB Slots, Internet, and
Touch Screen (flowing from the I/O Controller in Level 3).
Level 5 consists of the following components. Lowest
Manageable Subdeliverables are identified with an (*); Work
Packages are identified with a (#).
From Hardware (in Level 2)
• Frame*
o WP-F1#
• Cameras*
o WP-C1#
o WP-C2#
o WP-C3#
o WP-C4#
• Speakers*
o WP-S1#
• Antenna*
o WP-A1#
o WP-A2#
o WP-A3#
From Touch Screen (in Level 4)
• Keyboard*
o WP-K1#
• Touch Sensors*
o WP-TS1#
o WP-TS2#
o WP-TS3#
• Back Light*
o WP-BL1#
o WP-BL2#
23. function2();//call function 2
}
}
__MACOSX/._P1_NoThreads.java
Question1_WithdrawDeposit.javaQuestion1_WithdrawDeposit.j
avapackageThreads_Synchronization;
import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
publicclassQuestion1_WithdrawDeposit{
/*
* In this question use semaphore(s) to enable process synchr
onization
*
* Thread 1 and thread 2 (in the main function) share a single
bank account (initial balance of 1000$).
* thread 1 can deposit certain input amount to the balance on
ly if the current balance is less than 2000$
* thread 2 can withdraw certain input amount from the balan
ce only if the current balance is greater than or equal to the inpu
t amount.
*
*/
// shared resources between thread 1 and thread 2 are:
publicstaticint balance =1000;//the initial value of the account's
balance
24. //DONOT CHANGE THIS VARIABLE
// add below any further resources you think the deposit and wit
hdraw threads/functions must share
//--------------------------------------------
end of shared resources section
// this function simply displays the current balance of the shared
account and which thread made the call
// DONOT CHANGE THIS FUNCTION
publicstaticvoid displayStatus(){
if(Thread.currentThread().getName().equals("withdraw"))
System.out.println("The withdraw function successfully took th
e amount and the current value of the account's balance is :"+ b
alance +"$");
else
System.out.println("The deposit function successfully added the
amount and the current value of the account's balance is :"+ bal
25. ance +"$");
}
// this function accepts an input integer amount value to deposit
into the shared account
publicstaticvoidDeposit(int amount){
try{
System.out.println("The deposit function is trying to add "+ am
ount +"$ to the shared balance"+ balance +"$");
// Deposit the input amount to the balance only if the current bal
ance is less than 2000$
// Deposit doesn't wait until this condition is true (If the conditi
on is false, skip adding the amount), thus use if statements rathe
r than waiting while loops
// Call the displayStatus() function after you deposit the amount
and before release the lock
// Implement the deposit functionality, as detailed above, in the
area below
26. //--------------------------------------------end of Deposit function
}catch(Exception e){
System.out.println("Problem with the deposite function "+e.toSt
ring());
}
}
// this function accepts an input integer amount value to withdra
w from the shared account
publicstaticvoidWithdraw(int amount){
try{
System.out.println("The withdraw is trying to remove "+ amoun
t +"$ from the shared balance"+ balance +"$");
// withdraw the input amount from the balance only if the curren
t balance is greater than or equal to input amount
// Withdraw doesn't wait until this condition is true (if the condi
tion is false, skip withdrawing the amount), thus use if statemen
ts rather than waiting while loops
// Call the displayStatus() function after you remove the amount
and before release the lock
// Implement the withdraw functionality, as detailed above, in th
e area below
27. //--------------------------------------------
end of Withdraw function
}catch(Exception e){
System.out.println("Problem with the withdraw function "+e.toS
tring());
}
}
// this is the main function
// DONOT CHANGE THIS SECTION
publicstaticvoid main(String[] args){
//create thread 1 to run function 1
Thread thread1 =newThread(newRunnable(){
@Override
publicvoid run(){
while(true){
try{
Deposit(200+(int)(Math.random()*1000));//random value betwe
en 200 and 1000$
Thread.sleep(200+(int)(Math.random()*500));//random delay be
tween 200 and 500
}catch(Exception e){
System.out.println("Problem with thread 1 "+e.toString());
}
}
28. }
});
//create thread 2 to run function 2
Thread thread2 =newThread(newRunnable(){
@Override
publicvoid run(){
while(true){
try{
Withdraw(200+(int)(Math.random()*1000));//random value bet
ween 200 and 1000$
Thread.sleep(200+(int)(Math.random()*500));//random delay be
tween 200 and 500
}catch(Exception e){
System.out.println("Problem with thread 2 "+e.toString());
}
}
}
});
//ask the threads to start running
thread1.setName("deposit");
thread1.start();
thread2.setName("withdraw");
thread2.start();
}
}
__MACOSX/._Question1_WithdrawDeposit.java
P4_Semaphore.javaP4_Semaphore.javapackageThreads_Synchro
nization;
29. import java.util.concurrent.*;
publicclassP4_Semaphore{
/*
Important to note:
Mutex Lock in literature uses acquire() and release()
in Java these functions are lock() and unlock() r
espectively
Semaphore in literature uses wait() and signal()
in Java these functions are acquire() and release(
) respectively
*/
//semaphore lock
//counting semaphore with two instances, change the number of
instances and track the acquire/release sequence
publicstaticSemaphore semaphore =newSemaphore(2);
publicstaticvoid function1(){
for(int i=0;i<5;i++){
try{
System.out.println("function 1 trying to acquire the lock");
semaphore.acquire();
30. System.out.println("function 1 acquired the lock ... start the crit
ical section");
//critical section
System.out.println("function 1 Locks remaining >> "+semaphor
e.availablePermits());
//end of critical section
semaphore.release();
System.out.println("exit the critical section ... function 1 Locks
Released");
}catch(Exception e){
e.printStackTrace();
}
}
}
publicstaticvoid function2(){
for(int j=0;j<5;j++){
try{
System.out.println("function 2 trying to acquire the lock");
semaphore.acquire();
System.out.println("function 2 acquired the lock ... start the crit
ical section");
//critical section
System.out.println("function 2 Locks remaining >> "+semaphor
e.availablePermits());
//end of critical section
31. semaphore.release();
System.out.println("exit the critical section ... function 2 Locks
Released");
}catch(Exception e){
e.printStackTrace();
}
}
}
publicstaticvoid main(String[] args){
//create thread 1 to run function 1
Thread thread1 =newThread(newRunnable(){
@Override
publicvoid run(){
function1();
}
});
//create thread 2 to run function 2
Thread thread2 =newThread(newRunnable(){
@Override
publicvoid run(){
function2();
}
});
thread1.start();
thread2.start();
}
33. //create thread 1 to run function 1
Thread thread1 =newThread(newRunnable(){
@Override
publicvoid run(){
function1();
}
});
//create thread 2 to run function 2
Thread thread2 =newThread(newRunnable(){
@Override
publicvoid run(){
function2();
}
});
//ask the threads to start running
thread1.start();
thread2.start();
}
}
__MACOSX/._P2_SimpleThreads.java
Question3_SortingArrays.javaQuestion3_SortingArrays.javapac
kageThreads_Synchronization;
import java.util.Random;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
publicclassQuestion3_SortingArrays{
34. /*
* In this question use mutex lock(s) or semaphore(s) to enab
le process synchronization
*
* Thread 1 and thread 2 share a single buffer (1D Array), wh
ere:
* thread 1 sorts the items of the buffer in ascending order
* thread 2 sorts the items of the buffer in descending order
*
*/
// shared resources between thread 1 and thread 2 are:
// DONOT CHANGE THESE VARIABLE
publicstaticintBufferSize=10;//the size of the buffer
publicstaticint buffer[]=newint[BufferSize];//the shared buffer
// add any further resources you think Ascending() and Descendi
ng()functions must share below
//--------------------------------------------
end of shared resources section
35. // this function simply displays the content of the shared buffer
and which thread made the call
// DONOT CHANGE THIS FUNCTION
publicstaticvoid displayStatus(){
if(Thread.currentThread().getName().equals("ascending"))
System.out.println("Ascending successfully sorted the array");
else
System.out.println("Descending successfully sorted the array");
System.out.print(" the "+Thread.currentThread().getName()+" is
displaying the content of the buffer: ");
for(int i=0;i<BufferSize;i++){
System.out.print(buffer[i]+" ");
}
System.out.println();
}
// this function sorts the shared buffer in ascending order
publicstaticvoidAscending(){
try{
System.out.println("The Ascending is trying to sort the shared b
uffer");
// Sort the buffer in ascending order
// Call displayStatus after you sort and before release the lock
// Implement the Ascending functionality in the area below
36. //--------------------------------------------
end of Ascending function
}catch(Exception e){
System.out.println("Problem with the Ascending function "+e.to
String());
}
}
// this function sorts the shared buffer in descending order
publicstaticvoidDescending(){
try{
System.out.println("The Descending is trying to sort the shared
buffer");
// Sort the buffer in descending order
// Call displayStatus after you sort and before release the lock
// Implement the Descending functionality in the area below
37. //--------------------------------------------
end of Descending function
}catch(Exception e){
System.out.println("Problem with the Descending function "+e.t
oString());
}
}
// this is the main function
// DONOT CHANGE THIS SECTION
publicstaticvoid main(String[] args){
for(int i=0;i<BufferSize;i++){
buffer[i]=1+newRandom().nextInt(9);//random value be
tween 1 and 10
}
//create thread 1 to run function 1
Thread thread1 =newThread(newRunnable(){
@Override
38. publicvoid run(){
while(true){
try{
Ascending();//sort in ascending order the shared buffer
Thread.sleep(200+(int)(Math.random()*500));//random delay be
tween 200 and 500
}catch(Exception e){
System.out.println("Problem with thread 1 "+e.toString());
}
}
}
});
//create thread 2 to run function 2
Thread thread2 =newThread(newRunnable(){
@Override
publicvoid run(){
while(true){
try{
Descending();//sort in ascending order the shared buffer
Thread.sleep(200+(int)(Math.random()*500));//random delay be
tween 200 and 500
}catch(Exception e){
System.out.println("Problem with thread 2 "+e.toString());
}
}
}
});
39. //ask the threads to start running
thread1.setName("ascending");
thread1.start();
thread2.setName("descending");
thread2.start();
}
}
__MACOSX/._Question3_SortingArrays.java
Question2_ProducerConsumer.javaQuestion2_ProducerConsume
r.javapackageThreads_Synchronization;
import java.util.Random;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
publicclassQuestion2_ProducerConsumer{
/*
* In this question use mutex lock(s) to enable process synchr
onization
*
* Thread 1 and thread 2 share a single buffer (1D Array), wh
ere:
* thread 1 adds item to the shared buffer only if there is a fr
ee space
* thread 2 consumes item from the shared buffer only if ther
40. e is an available item in the buffer
*
*/
// shared resources between thread 1 and thread 2 are:
// DONOT CHANGE THESE VARIABLE
publicstaticintBufferSize=5;//the size of the buffer
publicstaticint count =0;//keeps track of the number of items cur
rently in buffer
publicstaticint buffer[]=newint[BufferSize];//the buffer to add d
ata into and consume data from
// add below any further resources you think the producer and c
onsumer functions must share
//--------------------------------------------
end of shared resources section
// this function simply displays the content of the shared buffer
and which thread made the call
// DONOT CHANGE THIS FUNCTION
publicstaticvoid displayStatus(){
if(Thread.currentThread().getName().equals("producer"))
41. System.out.println("Producer successfully added the new item t
o the shared buffer");
else
System.out.println("Consumer successfully removed an item fro
m the shared buffer");
System.out.print(" the "+Thread.currentThread().getName()+" is
displaying the content of the buffer: ");
for(int i=0;i<BufferSize;i++){
System.out.print(buffer[i]+" ");
}
System.out.println(" and the value of the count is "+ count);
}
// this function accepts an input integer item to be added to the s
hared buffer
publicstaticvoidProducer(int item){
try{
System.out.println("The Producer is trying to add the new item
("+ item +") to the shared buffer");
// Add the input item only if there is a free space in the shared b
uffer
// Producer waits until this condition is true, thus use while rath
er than if statements
// Call the displayStatus() function after you add the item and b
efore release the lock
// Implement the producer functionality in the area below
42. //--------------------------------------------end of Producer function
}catch(Exception e){
System.out.println("Problem with the producer function "+e.toS
tring());
}
}
// this function removes an item from the shared buffer
publicstaticvoidConsumer(){
try{
System.out.println("The Consumer is trying to consume the read
y item from the buffer");
// Consume one item (overwrite its value with -
1) from the buffer only if there is an available item in the buffer
// Consumer waits until this condition is true, thus use while rat
her than if statements
// Call the displayStatus() function after you remove the item an
d before release the lock
// Implement the consumer functionality in the area below
43. //--------------------------------------------
end of Consumer function
}catch(Exception e){
System.out.println("Problem with the consumer function "+e.to
String());
}
}
// this is the main function
// DONOT CHANGE THIS SECTION
publicstaticvoid main(String[] args){
count =0;
for(int i=0;i<BufferSize;i++){
buffer[i]=-1;//free spots
}
//create thread 1 to run function 1
44. Thread thread1 =newThread(newRunnable(){
@Override
publicvoid run(){
while(true){
try{
Producer(1+newRandom().nextInt(9));//random value between 1
and 10
Thread.sleep(200+(int)(Math.random()*500));//random delay be
tween 200 and 500
}catch(Exception e){
System.out.println("Problem with thread 1 "+e.toString());
}
}
}
});
//create thread 2 to run function 2
Thread thread2 =newThread(newRunnable(){
@Override
publicvoid run(){
while(true){
try{
Consumer();
Thread.sleep(200+(int)(Math.random()*500));//random delay be
tween 200 and 500
}catch(Exception e){
System.out.println("Problem with thread 2 "+e.toString());
}
45. }
}
});
//ask the threads to start running
thread1.setName("producer");
thread1.start();
thread2.setName("consumer");
thread2.start();
}
}
__MACOSX/._Question2_ProducerConsumer.java
P3_MutexLocks.javaP3_MutexLocks.javapackageThreads_Sync
hronization;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
publicclassP3_MutexLocks{
/*
Important to note:
Mutex Lock in literature uses acquire() and release()
in Java these functions are lock() and unlock() r
espectively
Semaphore in literature uses wait() and signal()
in Java these functions are acquire() and release(
) respectively
*/
46. publicstaticLock lock =newReentrantLock();//mutex lock
publicstaticint count =0;//shared variable
publicstaticvoid function1(){
for(int i=0;i<5;i++){
try{
System.out.println("function 1 trying to acquire the lock");
lock.lock();
System.out.println("function 1 acquired the lock ... start the crit
ical section");
//critical section
count++;
System.out.println("function 1 updated the count to "+ count);
//end of critical section
lock.unlock();
System.out.println("exit the critical section ... function 1 releas
ed the lock");
}catch(Exception e){
e.printStackTrace();
}
}
}
47. publicstaticvoid function2(){
for(int j=0;j<5;j++){
try{
System.out.println("function 2 trying to acquire the lock");
lock.lock();
System.out.println("function 2 acquired the lock ... start the crit
ical section");
//critical section
count++;
System.out.println("function 2 updated the count to "+ count);
//end of critical section
lock.unlock();
System.out.println("exit the critical section ... function 2 releas
ed the lock");
}catch(Exception e){
e.printStackTrace();
}
}
}
publicstaticvoid main(String[] args){
//create thread 1 to run function 1
Thread thread1 =newThread(newRunnable(){
@Override
publicvoid run(){
function1();
}
});
48. //create thread 2 to run function 2
Thread thread2 =newThread(newRunnable(){
@Override
publicvoid run(){
function2();
}
});
thread1.start();
thread2.start();
}
}
__MACOSX/._P3_MutexLocks.java
Operating System - Assignment II
Mutex locks and semaphores, as discussed in class, are different
techniques to solve the race condition and
to ensure an efficient synchronization between cooperating
threads and processes. In this assignment, you
will use locks and semaphores to solve several synchronization
problems between cooperating threads. You
can develop the required work either on your computer or on the
Ubuntu VM you installed, and you can
use any Java IDE you find appropriate (e.g., NetBeans, Eclipse,
IntelliJ). Follow the video posted on D2L;
in this video, you will create a new Java program and package
before you copy a number of .java files to
your project. This video shows how to use mutex lock and
semaphore between cooperating threads. As
discussed and shown in the video, it is important to note that:
49. • Mutex Lock, in literature, uses acquire() and release().
However, in the standard library of Java, these
functions are lock() and unlock(), respectively. The same
functionalities but with different names.
• Semaphore, in literature, uses wait() and signal(). However, in
the standard library of Java, these functions
are acquire() and release(), respectively. The same
functionalities but with different names.
Task description:
The files (named question1, question2, and question3) are for
three different synchronization problems,
with a full Java skeleton. The comments in the Java files
explain in detail the required functionalities and
guide you to where exactly you should place your
implementation, read them carefully before starting
coding. DO NOT CHANGE any already existing code (e.g.,
function name, variable name).
• In the first question, the deposit and withdraw functions share
a bank account to add a certain amount or
subtract a certain amount from the balance, respectively. Use
semaphore(s) to implement the
synchronization.
•
• In the second question, the producer and consumer functions
share an array of integer values to add items
or remove items from the buffer, respectively. Use mutex
lock(s) to implement the synchronization.
•
50. • In the third question, the Ascending and Descending functions
share an array of integer values to sort
them in ascending or descending order, respectively. Use either
mutex lock(s) or semaphore(s) to
implement the synchronization. Implement the sorting method
you find appropriate (e.g., selection sort,
bubble sort, insertion sort), but don’t use collection
methods/APIs (e.g., Arrays.sort).
Note: the threads running the above questions are implemented
to run in an infinite loop, so at some
point, you may need to force-stop the program.
Submission:
1. This is an individual assignment -- Cheating/plagiarism will
be checked and will receive zero.
2. Your submission to the folder titled Assignment 2 under the
D2L Assignments tab contains the following:
a. The three java files you worked on
b. One Runtime.pdf: - For each of the three java files, copy the
full java code and add a
clear screenshot of the output after running the code.
* these are separate files within your submission, don’t submit a
zip file
3. The assignment is due October 21st – 11:59pm. You can
submit your assignment within 24 hours
after this due date to be graded out of 50% of the assignment’s
51. grade. After this grace period, your
late submission will not be accepted.
· Identify a personal project of your choosing. This could be a
family vacation, plans to clean or organize a part of your living
space, etc.
· For the discussion, you will use the tools provided in Chapter
4 of your textbook to provide a brief summary of your project
that includes the scope of the project and at least three goals or
objectives of the project.