[Vm-dev] Re: Efficient thread-local shared variables

Klaus D. Witzel klaus.witzel at cobss.com
Tue Oct 24 08:10:55 UTC 2006


Hi Nicolas,

on Tue, 24 Oct 2006 09:39:31 +0200, you wrote:
> Hi Klaus and Andreas
> I find the local shared variable feature most useful.
> I'am trying to understand your suggestions,
...
> Klaus:
> - have a single SharedPool with values being an array, and an index per  
> process?

No, one Array per process and one integer index per shared variable.

>   pseudo code for PerProcessThing:
>   PerProcessThing localSharedValue
>   where localSharedValue is (^self at: Processor activeProcess  
> processIndex)

No, Association subclass #LocalSharedVariable and then
LocalSharedVariable>>localSharedValue
	<primitive: 4711>
	"this is what the primitive does faster:"
	^ Processor activeProcess scope localSharedArray at: value

LocalSharedVariable's key is the same as the key in the PerProcessThing  
association (for convenience), and LocalSharedVariable's value is the  
integer index into the localSharedArray.

If you spend a primitive implementation and suppose that the example  
compiles to

	pushLiteralVariable: (#PerProcessThing -> aLocalSharedVariable)
	send: #localSharedValue "handled by primitive 4711"

So exactly two bytecodes (without context switch) and, since you at least  
need to tell a "descriptor" and what you want from it (get or set a  
value), this identifies the least number of bytecodes necessary.

> - have to reset all the shared value arrays each time a process is  
> created or die...

This is independent of any proposal, you always have to allocate the  
shared value array per process, like in
	[[self allocateSharedValueArray.
	 self doTheJob] ensure:
	 [self destroySharedValueArray]] fork

> I am not sure i understood well Klaus proposition
> Did i get it ?

I think so :)

/Klaus

> Nicolas
>
> Le Mardi 24 Octobre 2006 07:33, Klaus D. Witzel a écrit :
>> Hi Andreas,
>>
>> on Tue, 24 Oct 2006 06:46:26 +0200, you wrote:
>> > Folks -
>> >
>> > For a variety of reasons I am in dire need of the ability to vector
>> > shared variables (globals, class vars and pool vars) through an extra
>> > indirection vector per process (really per island but binding per
>> > process seems to be simpler for now). Since I need this for *each and
>> > every shared variable* it needs to be *very* efficient.
>> >
>> > The question is: What is the most efficient way to implement such a
>> > scheme?
>>
>> The fastest indirect access is through literal variables (limited only  
>> by
>> the # of literals allowed per method).
>>
>> Since you are willing to spend a #symbol per variable, formally declare  
>> a
>> "descriptor" to be a class var (or use a pool). Take #PerProcessThing as
>> as example; initialize PerProcessThing to a subinstance of Association
>> which holds a fast and fixed Array index.
>>
>> Then all you need in the scope of activeProcess is a shared Array which  
>> is
>> indexed by the above machinery. Example use:
>>
>> 	PerProcessThing localSharedValue
>> 	PerProcessThing localSharedValue: somethingElse
>>
>> Not counting "Processor activeProcess scope", the above is the fastest
>> double-indirect access that I can think of.
>>
>> /Klaus
>
>
>
> ________________________________________________________________________
> iFRANCE, exprimez-vous !
> http://web.ifrance.com




More information about the Vm-dev mailing list