Hey guys i need some help to understand how to do this exercise:
"Write a program in which two threads write random numbers on a global vector of integers and size 100. These threads should use mutexes to get the value that indicates the position to be filled in the vector. This value starts at -1 and each thread should increase it before you use it . When the vector is filled in the original thread must be agreed by a condition variable ."
I use google translate.
I dont want you to solve my exercise i want a help about work with mutexes. I search here and understand a litle bit with the chicken history "What is a mutex?" but I don't know how to do it. This is like a challenge that the teacher made for us and he didn't explain about mutex.
here it's the beginning of my code with only 1 thread for now.
import java.util.Random; public class ThreadRandomNumbersClass {
public static class RunnableT1 implements Runnable{
@Override
public void run(){
int i;
int array[] = new int[100];
Random rn = new Random();
for(i=0; i<100; i++){
array[i] = rn.nextInt();
System.out.println(array[i]);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Thread t1 = new Thread(new RunnableT1());
t1.start();
}
}
Aucun commentaire:
Enregistrer un commentaire