-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLockFreeSetThread.java
More file actions
45 lines (41 loc) · 1.2 KB
/
LockFreeSetThread.java
File metadata and controls
45 lines (41 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.Random;
public class LockFreeSetThread extends Thread {
static LockFreeSet s = new LockFreeSet();
Random rand = new Random();
char currentArgument;
public LockFreeSetThread(int id) {
super(id);
}
public Method nextMethod() {
Method m = null;
currentArgument = (char)(rand.nextInt(26) + 'a');
switch(rand.nextInt(3)) {
case 0:
m = new LockFreeSetAdd(s.getHead(), currentArgument, getThreadId());
break;
case 1:
m = new LockFreeSetRemove(s.getHead(), currentArgument, getThreadId());
break;
case 2:
m = new LockFreeSetContains(s.getHead(), currentArgument, getThreadId());
break;
case 3:
System.out.println("no method found");
}
return m;
}
public boolean betweenMethods() {
return currentMethod == null;
}
public String getState() {
return s.toString();
}
public static void main(String args[]) {
LockFreeSetThread threads[] = new LockFreeSetThread[10];
for (int i = 0; i < threads.length; i++) {
threads[i] = new LockFreeSetThread(i);
}
iterate(threads);
System.out.println(s);
}
}