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 specified size.•int barrier point(void)—identifiesthe 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:30
Larry sent an email to andy. andy didn't open larry's email but still understood what the message was. how did andy determine the message without opening the email?
Answers: 1
question
Computers and Technology, 22.06.2019 11:30
Awell-diversified portfolio needs about 20-25 stocks from different categories.
Answers: 2
question
Computers and Technology, 22.06.2019 14:30
Hi plz 11 ! when planning a table, what step comes first: "define the column headers" or "calculate the number of columns/rows"? a. calculate the number of columns/rows b. define the column headers
Answers: 1
question
Computers and Technology, 22.06.2019 15:00
Which of the following has not been attributed at least in part to social media a. drug addiction b. depression c. kidnapping d. murder
Answers: 2
You know the right answer?
Implement the following project using: a) cb) javaa barrier is a tool for synchronizing the activity...
Questions
question
Physics, 01.12.2020 16:20
question
Mathematics, 01.12.2020 16:20
question
Mathematics, 01.12.2020 16:20
question
Computers and Technology, 01.12.2020 16:20
Questions on the website: 13722360