Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void atLeastOne(int n, Runnable r){
- Thread[] t = new Thread[n];
- for(int i=0;i<n;i++)
- t[i] = new Thread(){
- public void run(){
- r.run();
- if(!isInterrupted()){
- for(Thread x : t)
- if(x != currentThread())
- x.interrupt();
- }
- }
- };
- for(Thread x : t)
- x.start();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement