1761
|
1 |
"{ Package: 'stx:libjava/benchmarks' }"
|
|
2 |
|
|
3 |
JavaBenchmark subclass:#Threadring
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Benchmarks-Java-Micro'
|
|
8 |
!
|
|
9 |
|
|
10 |
Object subclass:#Thread
|
|
11 |
instanceVariableNames:'name nextThread token semaphore done'
|
|
12 |
classVariableNames:''
|
|
13 |
poolDictionaries:''
|
|
14 |
privateIn:Threadring
|
|
15 |
!
|
|
16 |
|
|
17 |
|
1762
|
18 |
!Threadring methodsFor:'benchmarking'!
|
|
19 |
|
|
20 |
threadRing: aSemaphore
|
|
21 |
| first last |
|
|
22 |
503 to: 1 by: -1 do: [:i|
|
|
23 |
first := Thread named: i next: first done: aSemaphore.
|
|
24 |
last isNil ifTrue: [ last := first ].
|
|
25 |
].
|
|
26 |
last nextThread: first.
|
|
27 |
^first
|
|
28 |
! !
|
|
29 |
|
1761
|
30 |
!Threadring methodsFor:'running'!
|
|
31 |
|
1762
|
32 |
runBenchmarkS:n
|
|
33 |
^ 'N/A'
|
1761
|
34 |
|
|
35 |
"Created: / 31-10-2012 / 10:22:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
36 |
! !
|
|
37 |
|
|
38 |
!Threadring::Thread class methodsFor:'instance creation'!
|
|
39 |
|
|
40 |
named: anInteger next: aThread done: aSemaphore
|
|
41 |
^self new name: anInteger; nextThread: aThread; done: aSemaphore; fork
|
|
42 |
!
|
|
43 |
|
|
44 |
new
|
|
45 |
^self basicNew semaphore: Semaphore new
|
|
46 |
! !
|
|
47 |
|
|
48 |
!Threadring::Thread methodsFor:'accessing'!
|
|
49 |
|
|
50 |
done: aSemaphore
|
|
51 |
done := aSemaphore
|
|
52 |
!
|
|
53 |
|
|
54 |
fork
|
|
55 |
[ self run ] fork
|
|
56 |
!
|
|
57 |
|
|
58 |
name: anInteger
|
|
59 |
name := anInteger
|
|
60 |
!
|
|
61 |
|
|
62 |
nextThread: aThread
|
|
63 |
nextThread := aThread
|
|
64 |
!
|
|
65 |
|
|
66 |
run
|
|
67 |
[ self tokenNotDone ] whileTrue: [ nextThread takeToken: token - 1 ].
|
|
68 |
done signal
|
|
69 |
!
|
|
70 |
|
|
71 |
semaphore: aSemaphore
|
|
72 |
semaphore := aSemaphore
|
|
73 |
!
|
|
74 |
|
|
75 |
takeToken: x
|
|
76 |
token := x.
|
|
77 |
semaphore signal
|
|
78 |
!
|
|
79 |
|
|
80 |
tokenNotDone
|
|
81 |
semaphore wait.
|
|
82 |
^token > 0
|
|
83 |
! !
|
|
84 |
|
|
85 |
!Threadring class methodsFor:'documentation'!
|
|
86 |
|
|
87 |
version_SVN
|
|
88 |
^ '$Id:: $'
|
|
89 |
! !
|