[Q] executing SOME compiledMethod (classless)
Viktor Zigo
viz at whitestein.com
Wed Apr 5 09:07:43 UTC 2000
Hi folks !
Recently there's been a discussion that my colleague Peter started, about the
possible solution for running a code concurrently without having any class for it.
For those, involved in this discussion I send a changeset of a simple solution we
us. So far it seems to fit to our requirements. If you want, check it out (there
are some tests with interesting results - speed)
viktor
Lex Spoon wrote:
> How about using blocks instead of CompiledMethod's? Blocks can be
> evaluated by sending #value. You could make the first argument of the
> block be the "receiver".
>
> -Lex
----
Whitestein Information Technology Group, Ltd
-------------- next part --------------
'From Squeak2.7 of 5 January 2000 [latest update: #1780] on 4 April 2000 at 10:48:23 am'!
Object subclass: #Classless
instanceVariableNames: 'code '
classVariableNames: ''
poolDictionaries: ''
category: 'test'!
Classless class
instanceVariableNames: ''!
!Classless commentStamp: 'vikiz 4/4/2000 10:47' prior: 0!
We show here the solutions (yet another trick without using primitives) that seems to fit our requirements: To concurrnetly run a piece of code that has no class and is binded to a receiver only to provide 'self' accessible.
This class contains some basic tests that show two different aproaches; using classes or using BlockContexts. (It's interesting that our aproach in several times faster !!!!) Are there some weak spots o in the method we use ? !
!Classless methodsFor: 'execution' stamp: 'vikiz 4/4/2000 10:10'!
execute: aBlock in: aReceiverThing with: anArgumentArray
"create unique context for each run. The code can run concurrently in many different contexts"
|newContext|
newContext _ aBlock copy.
newContext home: (aBlock home copy receiver: aReceiverThing).
newContext home sender: thisContext. "to allow returnTop from BlockContext"
^newContext valueWithArguments: anArgumentArray.
! !
!Classless methodsFor: 'testing' stamp: 'vikiz 4/4/2000 10:28'!
met: aNum
aNum>0 ifTrue: [^aNum].
^'ahoj' ! !
!Classless class methodsFor: 'testing' stamp: 'vikiz 4/4/2000 10:48'!
testUsingBlocks
"This way of execution doesn't need creation of any Class
for each prototype, providing also concurrent execution of a code (by proto's who share this code)"
| code proto |
code _ [:num |
num > 0 ifTrue: [^ num].
'ahoj'].
proto _ self new.
50000
timesRepeat:
[proto execute: code in: proto with: #( 3 ) ]! !
!Classless class methodsFor: 'testing' stamp: 'vikiz 4/4/2000 10:38'!
testUsingClass
"This way of execution of a code reqires each prototype to have
it's own Class to allow conurrent execution"
| code proto sel |
sel _ self compile: 'met: aNum
aNum>0 ifTrue: [^aNum].
^''ahoj'' '.
code _ self compiledMethodAt: sel.
proto _ self new.
50000
timesRepeat:
[proto class addSelector: #Do: withMethod: code.
proto perform: #Do: withArguments: #(1 )]! !
!BlockContext methodsFor: 'accessing' stamp: 'vikiz 4/4/2000 10:37'!
home: aContext
"Ugly trick"
home_ aContext! !
!MethodContext methodsFor: 'accessing' stamp: 'vik 4/1/2000 14:10'!
receiver:anObject
receiver_ anObject! !
!MethodContext methodsFor: 'accessing' stamp: 'vik 4/1/2000 15:10'!
sender: aContext
sender_aContext.! !
More information about the Squeak-dev
mailing list
|