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, 23.06.2019 01:00
Let r be a robotic arm with a fixed base and seven links. the last joint of r is a prismatic joint, the other ones are revolute joints. give a set of parameters that determines a placement of r. what is the dimension of the configuration space resulting from your choice of parameters?
Answers: 3
question
Computers and Technology, 23.06.2019 05:20
Which operating system is a version of linux?
Answers: 1
question
Computers and Technology, 24.06.2019 05:00
Who is most likely be your target audience if you create a slide presentation that had yellow background and purple text
Answers: 2
question
Computers and Technology, 24.06.2019 19:30
Can someone who is skilled at coding create me a java chess game. don't copy from online source codes. make it original ! : d
Answers: 1
You know the right answer?
Implement the following project using: a) cb) javaa barrier is a tool for synchronizing the activity...
Questions
question
Mathematics, 10.09.2019 23:30
Questions on the website: 13722360