Question: Read given code RaceOrNot 1 . java and write all possible outputs of the program when it is run as java RaceOrNot 1 3 .
Read given code RaceOrNotjava and write all possible outputs of the program when it is run as java RaceOrNot If you believe there is only one possible output, you just need to write that output.
Code:
Can you rewrite this program into an equivalent program using Lock or Semaphore instead of using synchronized?
public class RaceOrNot implements Runnable
static int numthreads;
static int sa;
int index;
RaceOrNotint x
indexx;
public void runimplement the method run in Runnable interface
synchronizedthis
forint i;i;i
saindexsaindex;
for
run
static void printSa
System.out.printlnStringvalueOfsaString.valueOfsa;
printSa
public static void mainString args
ifargslength!
System.err.printlnneed one command line argument n;
System.exit;
numthreadsInteger.parseIntargs;number of threads that the user inputs
ifnumthreads numthreads
System.err.printlnnumber of threads should be between and ;
System.exit;
RaceOrNot atnew RaceOrNotnumthreads;create array to hold task objects
Thread arrT new Threadnumthreads;create array to hold Thread objects
forint i;i
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
