Write a program that creates an array of length 10, then creates 8 threads. should request entrance to their critical sections that is controlled through semaphores, read the values written in the array, and write it to the screen with the following format: "Consumer number - consumed item number-with the value -" And to a file named "Consumer activity", then exit the critical section, and repeat till the producers stop production. The total number of elements generated by the producer and consumed by the consumers should be 10,000,000 number
Q: Roni and Rajesh love to play a rope-based game. The game is as follows. At first, Tracy writes a…
A: Algorithm: First input contains a single integer T, the number of test cases. Then the second line…
Q: Write the definition of the class linkedQueueType, which is derived from the class…
A: This solution has two files. name is mentioned in the step. please create both the files in the same…
Q: c. Write a Java a program with a main thread and two user threads, thrdl and thrd2. i) Have thrdl…
A: package prassu;import java.util.Scanner;public class myThread {public static void main(String[]…
Q: Implement the Round Robin Scheduler as described in attached notes “Round Robin Scheduler…
A: Answer :
Q: Consider the BadReaderWriter.java program attached with this homework. The program has three…
A: According to the infromation given:- we have to BadReaderWriter.java. It had 3 threads (reader,…
Q: you will create a spell checker. The program will take three command line arguments: number of words…
A: Filename: main.cpp #include <iostream> #include <string> #include "QuadraticProbing.h"…
Q: 3. Create a class with method to count odd and even number in 3X3 matrix. Create two threads to…
A: //find frequency of odd and even numbers in 3x3 matrix using Runnable interface class matrix…
Q: Write a multithreaded program (using pthread in Linux) that calculates various statistics values for…
A: Write a multithreaded program (using pthread in Linux) that calculatesvarious statistics values for…
Q: Part 3 One way to organize a collection of words is to use an array of sorted lists. The array…
A: Abstraction : One of the hard parts about PC writing computer programs is that, by and large,…
Q: Try the following commands in the C (CodeBlocks)"Interactions" pane and note what happens. Then try…
A: There are many languages which are used in today's wold. Computer language can be described as a…
Q: 4 Create a 10-D array with random digits (0-9) populated by 10 threads simultaneously. Scale the…
A: 4. import java.util.Random; import java.util.*; public class Main { public static void…
Q: c) Create a thread class named Worker that takes two positive integers, when it starts running, it…
A: ANSWER:-
Q: public class Facility implements Iterable { protected String name; } protected class StorageUnit {…
A: public class Facility implements Iterable { protected String name; protected class StorageUnit…
Q: neo Array length: 15 y name is heban :: created by Thread-0 nane is hebany :: created by Thread-1…
A: Our task: Provide a multithreaded java program to generate the output:
Q: In quicksort, after finishing the first partitioning, the array is looking like this: 25189 12 11 10
A: Step 1:- 8 and 9 are at their correct positionsAll elements on the left of 8 and 9 are smaller than…
Q: Write a multithreaded program using Pthreadlibraryin C++ that calculates various statistical…
A: Write a multithreaded program using Pthreadlibraryin C++ that calculates various statistical…
Q: Write a C program to implement threading. a. Use following two Arrays a. Student…
A: #include #include #include #include void* thread_1(void* arg) { int i; int *marks = (int…
Q: your program. #include int main (int argc, char *argv[]) { int i, thread id; int glob nloops, priv…
A: Here i filled up the blanks: ================================== 1.#pragma omp parallel…
Q: fork-join threading
A: Code: import java.util.Arrays;import java.util.concurrent.ForkJoinPool;import…
Q: Enter N For Nx2 Matrix: 3 homework3 [Java Application)…
A: Code import java.io.*;import java.util.*;class Main { static void rotate(int n, int matrix[][]){…
Q: The following recursive method is causing an exception because the base case is missing. This…
A: Here method print() will print element of array in reverse order. In this code we are passing last…
Q: In this part, you are required to write a program, using linked lists, that manipulates a set of…
A: #include <iostream>using namespace std;class cellphone{ private: long SerialNum;…
Q: Please use java Write a multithreaded program (using pthread in Linux) that calculates various…
A: Write a multithreaded program (using pthread in Linux) that calculatesvarious statistics values for…
Q: If in the ArrayStack, the first element that we push to the stack, is stored in location capacity -…
A: Let the capacity of stack be 10. If we perform the push in following order Push 2 Push 4 Push 6 Push…
Q: you will create a spell checker. The program will take three command line arguments: number of words…
A: #Code in C++ Filename: QuadraticProbing.cpp #include "QuadraticProbing.h"#include…
Q: Write a program such that the main method creates an array of 1000 double numbers and creates 10…
A: import java.lang.Math; class InitializeArray implements Runnable { private Thread t;…
Q: 8.11 LAB: Movie show time display Java Please Write a program that reads movie data from a csv…
A: ANSWER:-
Q: Below is a memory diagram of a LinkedIntList object. Which of the code fragments below the diagram…
A: Answer: Node newNode = new Node();newNode.item = 50;newNode.next = first.next;first.next = newNode;
Q: using C language Write a program that creates an array of length 10, then creates 8 threads. should…
A: Write a program that creates an array of length 10, then creates 8 threads. should request entrance…
Q: mplement the producer consumer problem (also known as bounded buffer problem) in java. create two…
A: producer : The producer’s job is to generate data, put it into the buffer. Consumer : The consumer…
Q: Write a windows32 assembly language program in visual studio that utilizes a recursive procedure.…
A: Using digital signal, function statements are: 1) That method has to be the same regardless of which…
Q: 4 Create a 10-D array with random digits (0-9) populated by 10 threads simultaneously. Scale the…
A: 4. import java.util.Random; import java.util.*; public class Main { public static void…
Q: implementation in Java
A: Introduction Java is a kind of programming language that provides a large number of applications…
Q: Write a server and client programs that do the following based on the written pseudocode: Client…
A: If one program is running into the network and a communication link is present within them then…
Q: Write a multithreaded program using Pthread library in C++ that calculates various statistical…
A: Program Approach:- Declaring the Global variables. Set length of the array to 7 as the given input…
Q: Write a function that will play Rock, Paper, Scissors with itself. It will pick two random elements…
A: Answer import random rps = [ 'rock' , 'paper' , 'scissors' ] rock = paper = scissors = 0 def…
Q: for this code explain How are the private variables created by the reduction parameter initialized?…
A: Definition: The reduction clauses are data-sharing attribute clauses that can be used to perform…
Q: Consider the BadReaderWriter.java program attached with this. The program has three threads, namely,…
A: Answer :
Q: We need to write a Java program that allows us to calculate the average grade in a class The program…
A: Solution Programming Approach Create class Grades.java Import necessary package Use he…
Q: Modify and run the program shown below in the following way. There is an array of 20 elements…
A:
Q: Write a multi-threading JAVA program that search creates a random array of integers (500 entries)…
A: The program is written in Java. Check the program screenshot for the correct indentation. Please…
Q: Create an application in Java that creates n (this is set at the beginning of the application not…
A: Given that, Create an application in Java that creates n (this is set at the beginning of the…
Q: Write a java application withtwothreads named “Thread-1” and “Thread-2”. The “Thread-1”reads the…
A: ANSWER:
Q: Write a Java program that simulates a basic library delivery system. The user of the program will be…
A: Program code: //import the required packagesimport java.io.*;import java.util.*;//define a class…
Q: Explain why synchronization is necessary in the following situation: You have modeled a bank as an…
A: Introduction: Synchronization is the process of managing multiple thread requests for resource…
Q: package Q2; import java.io.FileInputStream; import java.io.FileNotFoundException; import…
A: Code: package Q2; import java.io.FileInputStream; import java.io.FileNotFoundException; import…
Q: Write a multithreaded program (using pthread in Linux) that calculates various statistics values for…
A: Write a multithreaded program (using pthread in Linux) that calculatesvarious statistics values for…
Q: around a table with one chopstick between each of them. Let the Philosophers be numbered from 0 to…
A: Solution : As the code in the given question. This will lead to deadlock. Conditions of deadlock…
Q: Create an application in Java that creates n (this is set at the beginning of the application not…
A: The java code is gien below:-
using C language
Write a program that creates an array of length 10, then creates 8 threads.
should request entrance to their critical sections that is controlled through semaphores, read the values written in the array, and write it to the screen with the following format: "Consumer number - consumed item number-with the value -" And to a file named "Consumer activity", then exit the critical section, and repeat till the producers stop production. The total number of elements generated by the producer and consumed by the consumers should be 10,000,000 number
Step by step
Solved in 3 steps
- USE SIMPLE PYTHON Multithreading to perform parallel array summing. 1) Basic version with two levels of threads (master and slaves)One master thread aggregates and sums the result of n slave-threads where each slavethread sums a different range of values in an array of 1000 random integers (please program to generate 1000 random integers to populate the array). The number of slave-threads is a parameter which the user can change. For example, if the user chooses 4 slave threads, each slave thread will sum 1000/4 = 250 numbers. If the user chooses 3 slave threads, the first two may each sum 333 numbers and the third slave threadsums the rest 334 numbers. 2) Advanced version with more than two levels of threadsThe master thread creates two slave-threads where each slave-thread is responsible to sum half segment of the array. Each slave thread will fork/spawn two new slave-threads where each new slave-threadsums half of the array segment received by its parent. Each slave thread will…Write a program in Java programming: Imagine you have a static ArrayList that contains a list of numbers(Integer). Your task is to create two threads. One thread is adding random new numbers(1~100) into the list every 1 second. The second thread is removing all the odd numbers, and printing the list on the screen every 1.5 seconds. Your program should never end and please make sure to handle any race condition to avoid the ConcurrentModificationException. Please check below for a sample output. [][][48][48][48, 2][48, 2, 8][48, 2, 8, 80, 90][48, 2, 8, 80, 90][48, 2, 8, 80, 90, 94][48, 2, 8, 80, 90, 94, 28][48, 2, 8, 80, 90, 94, 28, 80][48, 2, 8, 80, 90, 94, 28, 80, 40]Debug this code in C so it runs. Here it is. Code: #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <pthread.h> void multiThreads(); void* threadFunction(void* vargp); void main(){ multiThreads(); return 0; } void multiThreads(){ int SIZE = 5; int i; int error; pthread_t tid[SIZE]; while(i < SIZE){ error = pthread_create(&(tid[i]), NULL, &threadFunction, (void*)&(tid[i])); if(error != 0){ printf("\nThread can't be created : [%s] \n Press 'Enter’ to continue...", strerror(error)); } i++; }//end while while(i < SIZE){ pthread_join(tid[i], NULL); i++; } } void* threadFunction(void* vargp){ int LOOP = 5; int i; int* myid = (int*)vargp; printf("\n-----------------------------\n"); printf("\nThread %i has started\n", myid); printf("\n-----------------------------\n"); for(i = 0; i <= LOOP; i++){ printf("\nThread ID %i is printing…
- Write a program in C which creates 10 POSIX threads. These threads must individuallygenerate arrays of 1.000 random integers between 1.000 and 9.999 (inclusive) and counthow many of these numbers are prime numbers.A Sudoku puzzle uses a 9 × 9 grid in which each column and row, as well as each of the nine 3 × 3 sub grids, must contain all the digits 1 ··· 9. Implement a multithreaded application in C using Pthreads that reads the solution from a text file and determines if the solution to a Sudoku puzzle is valid. Your solution must not use more than 11 threads. Use semaphores in your program to synchronize the threads.Write a Java program that incorporates a loop that prompts the user for student data. Student data are private fields in a student class including: String name String address double GPA Each student object is stored in a linked list. After the user completes the data entry, output the contents of the linked list in ascending sorted order by name to a regular text file that can be opened and viewed using a simple plain-text editor such as notepad. Validate numeric data for Grade Point Average (GPA).
- Twist this assembly code, but this time a program asks the user to write anything and the written text/string must be saved in the file created in the this code.GIVEN CODE: .model small.stack 60h.data filepath db "UC",0filepath2 db "USC\USCMain",0filepath3 db "USC\USCTalamban",0filepath4 db "USC\USCSouth",0filepath5 db "USC\USCNorth",0;for uc banfilepath6 db "USC\USCSouth\BSECE ",0filepath7 db "USC\USCSouth\BSCPE",0create db "USC\USCSouth\BSCPE\Cruz.doc",0handle dw ?data db "My Name is Cruz, Juan"data_size=$-offset data .codemov ax,@datamov ds,ax mov ah,39hlea dx, filepathint 21h mov ah,39hlea dx, filepath2int 21h mov ah,39hlea dx, filepath3int 21h mov ah,39hlea dx, filepath4int 21h mov ah,39hlea dx, filepath5int 21h mov ah,39hlea dx, filepath6int 21h mov ah,39hlea dx, filepath7int 21h mov ah, 3chmov cx, 0mov dx, offset createmov ah, 3chint 21hmov handle, ax mov bx, handlemov dx, offset datamov cx, data_sizemov ah, 40hint 21h mov ah,4chint 21h endPlease help me code in java: Write a program that reads two files “Data1.txt”, “Data2.txt”; adding their corresponding elements produces an output file “output.txt”. If the number of elements are not equal, fill the elements of the smaller file up with “0” s. Sample output: Elements of the “Data1.txt”: 3 5 7 8 9 Elements of the “Data2.txt”: 45 11 Elements of the “Output.txt”: 48 16 7 8Consider the BadReaderWriter.java program attached with this. The program has three threads, namely, one reader thread and two writer threads, and they all access the same list of numbers. The reader thread reads the list and prints it to the terminal. The writer threads append numbers to the list. At any point in time, if either of the writer threads finds that the list contains n elements, then it appends the number n + 1 to the list. Run this program, examine the output, and identify the problems.Fix these problems by implementing the acquireLock() and releaseLock() methods in the code.
- In Python write a function that will play Rock, Paper, Scissors with itself. It will pick two random elements from a list. Then the function must know if random element #1 won, lost or drawed. The list is rps=[‘rock’, ‘paper’, ‘scissors’] Then the function must add to a dictionary the number of times the first element won per option in the list. Example{‘rock’:’400’, ‘paper’:’300’, ‘scissors’:’300’ } You need to run this at least 1000 times. You can either create a single thread, or you can create multiple threads. You need to use the random module and the random.choice(LISTNAME) to pick a random element from a list. Here's what I have so far: import random rps = ["rock", "paper", "scissors"] NumRock = 0 NumPaper = 0 NumScissors = 0 rand1 = random.choice(rps) rand2 = random.choice(rps) if rand1 == rand2: print("it's a tie") elif rand1 == "rock": if rand2 == "scissors": NumRock += 1…Computer Science (JAVA computer science) DO NOT COPY AND PASTE THE ANSWER FROM THE FIRST OR SECOND TIME I POSTED THIS. THIS IS DONE IN JAVA, NOT C. this is the third time I have to post this. Using java, make an array of 100,000 random numbers, and a program that computes the sum of the numbers, and times how long it takes. The program needs to compare the amount of time it takes to compute the sum vs the # of threads used. The # of threads varies from 1 to 50. Every time it should be comparing the same array of numbers vs the number of threads, so I can see how the # of threads affects the time elapsed while the array is the constant variable. Please make a global variable that all of the threads can use, and use a single JAVA class. potential output: # of threads: X sum: _____ time: ____ # of threads: Y sum: _____ time: ____ etc... thanks. (you dont have to include all the numbers for the array, I can generate my own set from a txt file or whatever)Rewrite the program in Example 3-1. DigestThread class to output the result of each file on an output file for each one by assigning a new name for the output file. The language is Java Example 3-1. DigestThread import java.io.*; import java.security.*; import javax.xml.bind.*; // for DatatypeConverter; requires Java 6 or JAXB 1.0 public class DigestThread extends Thread { private String filename; public DigestThread(String filename) { this.filename = filename; } @Override public void run() { 56 | Chapter 3: Threads www.it-ebooks.info try { FileInputStream in = new FileInputStream(filename); MessageDigest sha = MessageDigest.getInstance("SHA-256"); DigestInputStream din = new DigestInputStream(in, sha); while (din.read() != -1) ; din.close(); byte[] digest = sha.digest(); StringBuilder result = new StringBuilder(filename); result.append(": "); result.append(DatatypeConverter.printHexBinary(digest)); System.out.println(result); } catch (IOException ex) {…