subject

Implement the following project using: a) cb) javaa barrier is a tool for synchronizing the activity of a number of threads. when a thread reaches abarrier point, it cannot proceed until all other threads have reached this point as well. when the last thread reaches the barrier point, all threads are released and can resume concurrent execution. assume that the barrier is initialized to n ā€”thenumber of threads that must wait at the barrier point: init(n); each thread then performs some work until it reaches the barrier point: /* do some work for awhile */barrier point(); /* do some work for awhile */using synchronization tools described in this chapter, construct a barrier that implements the following api: ā€¢int init(int n)ā€”initializesthe barrier to the speciļ¬ed size.ā€¢int barrier point(void)ā€”identiļ¬esthe barrier point. all threads are released from the barrier when the last thread reaches this point. the return value of each function is used to identify error conditions. each function will return 0 under normal operation and will return āˆ’1 if an error occurs. a testing harness is provided in the source code download to test your implementation of the barriertesting code : javaimport java. io.*; /*** a testing harness for the barrier class.** proper output is that we should see is that all threads* output an 'a' before reaching the barrier and then a 'b'* after proceeding through the barrier. therefore, output* should appear as a series of 'a's followed by an equal count* of 'b's. (there should not be an intermingling of 'a's and 'b's.*/public class testbarrier{ public static final int thread_count = 5; public static void main(string args[]) throws java. io. ioexception { system. out. println("proper output is that we should see is that all threads"); system. out. println("output an 'a' before reaching the barrier and then a 'b'"); system. out. println("after proceeding through the barrier. therefore, output"); system. out. println("should appear as a series of 'a's followed by an equal count"); system. out. println("of 'b's. (there should not be an intermingling of 'a's and 'b's."); system. out. println("\n\npress enter to begin the test: "); (new bufferedreader(new inputstreamreader(system.(); // initialize the barrier to the number of threads // waiting upon the barrier barrier barrier = new barrierimpl(thread_count); thread[] workers = new thread[thread_count]; for (int i = 0; i < workers. length; i++) { workers[i] = new thread(new worker(barrier)); workers[i].start(); } try { for (int i = 0; i < workers. length; i++) workers[i].join(); } catch (interruptedexception ie) { } system. out. println("\n\npress enter to begin the freeall() test: "); (new bufferedreader(new inputstreamreader(system.(); barrier = new barrierimpl(thread_count + 1); workers = new thread[thread_count]; for (int i = 0; i < workers. length; i++) { workers[i] = new thread(new worker(barrier)); workers[i].start(); } try { thread. sleep(3000); } catch (interruptedexception ie) { } barrier. freeall(); }}/*** a worker using the barrier*/class worker implements runnable{ private barrier parta; public worker(barrier parta) { this. parta = parta; } /** * each thread will do some work for awhile, and then * invoke a thread may proceed when all * other threads have arrived at the barrier. */ public void run() { system. out. println("a"); sleeputilities. nap(); parta. waitforothers(); system. out. println("b"); }}testing code : c/*** script for testing the barrier implementation.** usage: * ./testbarrier #include #include "barrier. h"int main(int argc, char *argv[]){ if (argc ! = 2) { fprintf(stderr,"usage: ./testbarrier \n"); return -1; } int i; int number = atoi(argv[1]); pthread_t workers[number]; if ( barrier_init(atoi(argv[1])) ! = 0) return -1; for (i = 0; i < number; i++) { pthread_create(& workers[i], 0, worker, 0); } for (i = 0; i < number; i++) pthread_join(workers[i], 0); return 0; }

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 02:00
Aisha has finished working on a word processing document that contains 15 pages. she has added some special elements in the first three pages, page 9 and 10, and page 15 from the document. she wants to print only these pages to see how they look. which option is the correct way to represent (in the print dialog box) the pages that aisha wants to print?
Answers: 3
question
Computers and Technology, 23.06.2019 02:00
Consider the following function main: int main() { int alpha[20]; int beta[20]; int matrix[10][4]; . . } a. write the definition of the function inputarray that prompts the user to input 20 numbers and stores the numbers into alpha. b. write the definition of the function doublearray that initializes the elements of beta to two times the corresponding elements in alpha. make sure that you prevent the function from modifying the elements of alpha. c. write the definition of the function copyalphabeta that stores alpha into the first five rows of matrix and beta into the last five rows of matrix. make sure that you prevent the function from modifying the elements of alpha and beta. d. write the definition of the function printarray that prints any onedimensional array of type int. print 15 elements per line. e. write a c11 program that tests the function main and the functions discussed in parts a through d. (add additional functions, such as printing a two-dimensional array, as needed.)
Answers: 3
question
Computers and Technology, 23.06.2019 09:30
Name the range function that would generate the following list of integers values: 0,1,2,3,4,5.
Answers: 1
question
Computers and Technology, 23.06.2019 13:30
Stops: using the information learned in this course, explain three things you will not do when driving. a. b. c. explain why you will not do these things when driving. starts: using the information learned in this course, explain three things you will do when driving. a. b. c. explain why you will do these particular things when driving. explain one thing you will stop doing as a passenger. explain one thing you will start doing as a passenger.
Answers: 3
You know the right answer?
Implement the following project using: a) cb) javaa barrier is a tool for synchronizing the activity...
Questions
question
History, 25.07.2019 20:10
question
English, 25.07.2019 20:10
Questions on the website: 13722367