Re: Dynamically changing code in a safe way

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Dynamically changing code in a safe way

Pharo Smalltalk Users mailing list
Thank you guys for your answers and (very very) sorry for the delay.

Yes. The "everything is an object" Makes things so simple and clear :)
For me, this means that Pharo ensures “structural consistency”. The functional coherence is not  however guaranteed. I mean, two objects will be existing at the same time instead of one and this implies that some operating rules may be broken. The evolving philosophers problem is a typical example of such a thing.

I shall play a bit with this and come back to you ;)
Abdelghani


On 23 Oct 2017, at 23:12, Richard Sargent <[hidden email]> wrote:
This is a great question, Abdelghani.

It comes down to the meaning of the phrase "everything is an object". When you wrote "currentBloc value", that caused the block [ 1 to:50 do: [:index |Transcript show: index. 100 milliSeconds asDelay wait]. Transcript cr. 1000 milliSeconds asDelay wait ] to evaluate. The fact that you hold a reference to that block elsewhere and change what object is referenced at some point does not change the fact that the block itself is executing.

Until your code executes currentBloc value again, it won't start the new block executing.

Imagine if I were to hand you a loaf of bread and tell you to feed it to the dog. If I were then to hand you another loaf of bread, the dog would continue eating the first loaf. We never told the dog to do anything else.




On Mon, Oct 23, 2017 at 1:53 PM, abdelghani ALIDRA via Pharo-users <[hidden email]> wrote:


---------- Forwarded message ----------
From: abdelghani ALIDRA <[hidden email]>
To: <[hidden email]>
Cc: 
Bcc: 
Date: Mon, 23 Oct 2017 20:53:51 +0000 (UTC)
Subject: Dynamically changing code in a safe way
Hi,



If I create a class HotSwapping with the instance variable currentBLoc (and the corresponding accessors) and the following methods :



HotSwapping>>initialize

        currentBloc := [ 1 to:50 do: [:index |Transcript show: index. 100 milliSeconds asDelay wait]. Transcript cr. 1000 milliSeconds asDelay wait ]



HotSwapping>>run

        [10 timesRepeat: [ currentBloc value ]] fork



I then do : obj := HotSwapping new run

The “funny” thing is that, when Transcript starts showing numbers, lets say : 12345678910 (i.e. the bloc is in the middle of its execution), I do obj currentBloc: [Transcript show: ‘Hello’;cr. 1000 milliSeconds asDelay wait ]



The Transcript does not stop showing numbers. It shows the Hello message only after the old bloc has finished executing (the entire line of number form 0 to 50 has been printed in the Transcript)



So why does not this happen this way? Why the assignment of the new code is delayed until the end of the bloc execution? is it something related to threads execution or does Pharo implement some safety hot swapping mechanisms?



Thanks in advance.

Abdelghani