annotate src/alice/test/concurrent/StartConcurrent.java @ 276:3e0d1ac4f4a8

Refactor iterating process with for-each sentence.
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Fri, 18 Oct 2013 01:51:15 +0900
parents 481f322b3206
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
77
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 package alice.test.concurrent;
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 import org.msgpack.type.ValueFactory;
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 import alice.codesegment.CodeSegment;
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 public class StartConcurrent extends CodeSegment {
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 private int count;
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 public StartConcurrent(int count) {
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 this.count = count;
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 }
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 @Override
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 public void run() {
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 int threadNum = Runtime.getRuntime().availableProcessors() * count;
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 AliceFinish cs1 = new AliceFinish(threadNum);
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 cs1.ds1.setKey("finish");
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 for (int i = 0; i < threadNum; i++) {
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 SleepCodeSegment cs2 = new SleepCodeSegment(i);
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 cs2.ds1.setKey("wait");
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 }
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 for (int i = 0; i < threadNum; i++) {
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 ods.put("local", "wait", ValueFactory.createNilValue());
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 }
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 }
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
481f322b3206 add test concurrent execution of code segment
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 }