[Vm-dev] Explicitly avoiding process switch

Henrik Johansen henrik.s.johansen at veloxit.no
Thu Aug 11 13:56:20 UTC 2011


On Aug 11, 2011, at 2:59 56PM, Igor Stasenko wrote:

> 
> On 11 August 2011 14:28, Henrik Johansen <henrik.s.johansen at veloxit.no> wrote:
>> 
>> 
>> On Aug 11, 2011, at 2:11 37PM, Igor Stasenko wrote:
>> 
>> On 11 August 2011 13:17, Nicolas Cellier
>> <nicolas.cellier.aka.nice at gmail.com> wrote:
>> 
>> I would properly comment the places where this "ATOMIC" operation is
>> 
>> really used.
>> 
>> Like in
>> AtomicQueueItem>>makeCircular? :)
>> 
>> 
>> I also remember discussion that some precautions in code to not insert
>> suspension point(s) in ProcessorScheduler/Process/or Semaphore..
>> but i forgot which one exactly.
>> Is it LinkedList>>removeLink:?
>> 
>> http://code.google.com/p/pharo/issues/detail?id=3498
>> So suspension points in remove:ifAbsent (as written now)  and removeLink: are ok.
>> Not in removeLink:ifAbsent: though.
>> Used to be:
>> link := self linkOf: aLinkOrObject ifAbsent: [^aBlock value].
>> self removeLink: link.
>> ^aLinkOrObject
> 
> i don't like this code, because it iterating list twice, first to find a link,
> and second time to remove it.
> 
> I don't think it is a big secret that removing an element from linked
> list could be done using single iteration :)

You really only need to iterate to find the correct one if passed a non-link.
So the following is probably better:

linkOf: anObject ifAbsent: errorBlock 
	anObject asLink == anObject ifTrue: [^anObject].
	self
		linksDo: [:el | el value = anObject
				ifTrue: [^ el]].
	^ errorBlock value



Then 

ll := LinkedList new.
link := ll addFirst: 5.
ll remove: link ifAbsent: [self halt]

works without halting as well :)

Cheers,
Henry


More information about the Vm-dev mailing list