Eric.
Premium
- 8,515
- GTP_Eric
- Ebiggs
I'm working on a project due next week that is for interprocess communication. Its the producer/consumer problem. Though none of that is really too important to my issue.
I'm doing this in Java because I don't know C, so instead I'm creating two threads and performing operations on an integer array instead of a file or on shared memory like the lab suggests. So in my Main class I have a 10-item integer array named "buffer" created. There is also an integer named "r" that I'm using Random() with to create the numbers that will go into the array (not much point in that to be honest, just doing it).
The threads' execution code is in their class file "ChildThread", and at the moment it looks like this:
The problem is that the variable "r" and the int array "buffer" are not visible inside this class where the actual operations are going to be done. What can I do to make that work?
I'm doing this in Java because I don't know C, so instead I'm creating two threads and performing operations on an integer array instead of a file or on shared memory like the lab suggests. So in my Main class I have a 10-item integer array named "buffer" created. There is also an integer named "r" that I'm using Random() with to create the numbers that will go into the array (not much point in that to be honest, just doing it).
The threads' execution code is in their class file "ChildThread", and at the moment it looks like this:
Code:
public class ChildThread extends Thread {
//variables
private String name;
//constructor
public ChildThread(String aName){
name = aName;
}
public void run(){
if (name.equals("Producer")){
int i = 0; //index value for buffer array
int data = r;
while (i < 10){
buffer[i] = r+1; ***THIS LINE IS WHERE THE PROBLEM IS***
}
}
if(name.equals("Consumer")){
int i = 0; //index value for buffer array
}
}
}
The problem is that the variable "r" and the int array "buffer" are not visible inside this class where the actual operations are going to be done. What can I do to make that work?