Reputation: 1187
In a program, I am trying to make unique id numbers. I used this way:
AtomicInteger count = new AtomicInteger(0);
count.incrementAndGet();
int pid = count.get();
System.out.println("pid: " + pid);
But my professor said this:
Another problem is the pid generation. All you are doing is getting the next integer starting from 0. What happens when you reach the end of the process table? You had to come up with your own pid generation algorithm that works according to the project specification, i.e. it cycles through the numbers 0 through 99, and then when it cycles back to the low number it starts with the lowest available pid. There are many ways to implement such an algorithm, but the simplest thing to do is to add 1 mod 100, then keep looking until you find an available pid. Of course that means you have to keep track of which pids are available.
How do I do that?
Upvotes: 1
Views: 1359
Reputation: 116306
To me your professor's explanation is quite clear - is there any specific part in it that you don't understand?
If you understand the individual parts, divide the task into smaller subtasks and implement those one by one. Like
Upvotes: 3