Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package FairSmokers;
- import java.util.Random;
- import java.util.concurrent.ThreadLocalRandom;
- import Smokers.GlobalState;
- import se.his.iit.it325g.common.AndrewsProcess;
- public class Agent implements Runnable {
- private int tobacco = 0;
- private int paper = 0;
- private int matches = 0;
- private int request = 0;
- @Override
- public void run() {
- while (true) {
- request = GlobalState.Ach4.receive();
- if(request == 0)
- {
- //Gets paper and matches, send to tobacco
- paper++;
- matches++;
- GlobalState.Sch0.send(0);
- }
- else if(request == 1)
- {
- //Gets tobacco and matches, send to paper
- tobacco++;
- matches++;
- GlobalState.Sch1.send(1);
- }
- else if(request == 2)
- {
- //Gets tobacco and paper, send to matches channel
- tobacco++;
- paper++;
- GlobalState.Sch2.send(2);
- }
- getState();
- GlobalState.Ach4.receive();
- tobacco = 0;
- paper = 0;
- matches = 0;
- }
- }
- public void getState(){
- System.out.println("A - tobacco:" + tobacco + " paper:" + paper
- + " matches:" + matches);
- }
- public void doThings(){
- AndrewsProcess.uninterruptibleMinimumDelay(ThreadLocalRandom
- .current().nextInt(500, 1000));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement