thread-ring Smalltalk VW #2 program
source code
"* The Computer Language Benchmarks Game
http://benchmarksgame.alioth.debian.org/
adapted from a program by Paolo Bonzini
contributed by Isaac Gouy
modified by Carlo Teixeira *"!
Smalltalk defineClass: #Thread
superclass: #{Core.Object}
indexedType: #none
private: false
instanceVariableNames: 'name nextThread token semaphore done '
classInstanceVariableNames: ''
imports: ''
category: 'BenchmarksGame'!
Smalltalk.Core defineClass: #BenchmarksGame
superclass: #{Core.Object}
indexedType: #none
private: false
instanceVariableNames: ''
classInstanceVariableNames: ''
imports: ''
category: ''!
!Core.BenchmarksGame class methodsFor: 'private'!
threadRing: aSemaphore
| first last |
503 to: 1 by: -1 do: [:i|
first := Thread named: i next: first done: aSemaphore.
last isNil ifTrue: [ last:=first. ].
].
last nextThread: first.
^first! !
!Core.BenchmarksGame class methodsFor: 'initialize-release'!
program
| n done |
n := CEnvironment commandLine last asNumber.
(self threadRing: (done := Semaphore new)) takeToken: n.
done wait.
^''! !
!Thread class methodsFor: 'instance creation'!
named: anInteger next: aThread done: aSemaphore
^self new name: anInteger; nextThread: aThread; done: aSemaphore; fork!
new
^self basicNew semaphore: Semaphore new! !
!Thread methodsFor: 'accessing'!
run
[semaphore wait.
0==token] whileFalse: [nextThread takeToken: token - 1].
name printOn: Stdout.
Stdout cr.
done signal!
fork
[ self run ] forkAt: Processor userBackgroundPriority.!
semaphore: aSemaphore
semaphore := aSemaphore!
done: aSemaphore
done := aSemaphore!
name: anInteger
name := anInteger!
nextThread: aThread
nextThread := aThread!
takeToken: x
token := x.
semaphore signal! !
notes, command-line, and program output
NOTES:
64-bit Ubuntu quad core
VisualWorks® Personal Use Edition Release 8.2 of July 15, 2016
Tue, 02 May 2017 19:12:50 GMT
MAKE:
cp /usr/local/src/vw8.2pul/image/visualnc64.im threadring.vw-2.vw_run.im
/usr/local/src/vw8.2pul/bin/linuxx86_64/vwlinuxx86_64 threadring.vw-2.vw_run.im -nogui -pcl MatriX -filein threadring.vw-2.vw -doit 'ObjectMemory snapshotThenQuit'
Autoloading MatriX from $(VISUALWORKS)/preview/matrix/MatriX.pcl
Autoloading Xtreams-Support from $(VISUALWORKS)/xtreams/Xtreams-Support.pcl
Autoloading Xtreams-Core from $(VISUALWORKS)/xtreams/Xtreams-Core.pcl
Autoloading Xtreams-Terminals from $(VISUALWORKS)/xtreams/Xtreams-Terminals.pcl
Autoloading Xtreams-Transforms from $(VISUALWORKS)/xtreams/Xtreams-Transforms.pcl
Autoloading Xtreams-Substreams from $(VISUALWORKS)/xtreams/Xtreams-Substreams.pcl
Autoloading Xtreams-Multiplexing from $(VISUALWORKS)/xtreams/Xtreams-Multiplexing.pcl
Filing in from:
threadring.vw-2.vw
BenchmarksGame class<private
BenchmarksGame class<initialize-release
Thread class<instance creation
Thread<accessing
/home/dunham/benchmarksgame_quadcore/threadring/tmp/threadring.vw-2.vw_run.im created at May 2, 2017 12:12:44 PM
4.42s to complete and log all make actions
COMMAND LINE:
/usr/local/src/vw8.2pul/bin/linuxx86_64/vwlinuxx86_64 threadring.vw-2.vw_run.im -nogui -evaluate "BenchmarksGame program" -a 50000000
PROGRAM OUTPUT:
292